Skip to content

Commit 2800824

Browse files
committed
dr_wav: Fix an underflow error with badly formed ADPCM encoded files.
Public issue #299
1 parent db6309b commit 2800824

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

dr_wav.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3841,6 +3841,11 @@ DRWAV_PRIVATE drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc on
38413841

38423842
/* We decode two samples per byte. There will be blockCount headers in the data chunk. This is enough to know how to calculate the total PCM frame count. */
38433843
totalBlockHeaderSizeInBytes = blockCount * (6*fmt.channels);
3844+
if (totalBlockHeaderSizeInBytes >= dataChunkSize) { /* <-- We'll be subtracting totalBlockHeaderSizeInBytes from dataChunkSize next so it must be validated. */
3845+
drwav_free(pWav->pMetadata, &pWav->allocationCallbacks);
3846+
return DRWAV_FALSE; /* Invalid file. */
3847+
}
3848+
38443849
pWav->totalPCMFrameCount = ((dataChunkSize - totalBlockHeaderSizeInBytes) * 2) / fmt.channels;
38453850
}
38463851
if (pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
@@ -3854,6 +3859,11 @@ DRWAV_PRIVATE drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc on
38543859

38553860
/* We decode two samples per byte. There will be blockCount headers in the data chunk. This is enough to know how to calculate the total PCM frame count. */
38563861
totalBlockHeaderSizeInBytes = blockCount * (4*fmt.channels);
3862+
if (totalBlockHeaderSizeInBytes >= dataChunkSize) { /* <-- We'll be subtracting totalBlockHeaderSizeInBytes from dataChunkSize next so it must be validated. */
3863+
drwav_free(pWav->pMetadata, &pWav->allocationCallbacks);
3864+
return DRWAV_FALSE; /* Invalid file. */
3865+
}
3866+
38573867
pWav->totalPCMFrameCount = ((dataChunkSize - totalBlockHeaderSizeInBytes) * 2) / fmt.channels;
38583868

38593869
/* The header includes a decoded sample for each channel which acts as the initial predictor sample. */
@@ -8578,6 +8588,7 @@ DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b)
85788588
REVISION HISTORY
85798589
================
85808590
v0.14.6 - TBD
8591+
- Fix an underflow error with badly formed ADPCM encoded files.
85818592
- Fix an underflow error with badly formed W64 files.
85828593
- Fix an error when converting from >32 bit samples to s16/f32/s32 on big-endian architectures.
85838594

0 commit comments

Comments
 (0)