Skip to content

Commit

Permalink
Fix scenario where malformed dwa file could read past end of buffer (A…
Browse files Browse the repository at this point in the history
…cademySoftwareFoundation#1439)

Fixes OSS-Fuzz 59382

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed May 29, 2023
1 parent e084509 commit 9d82c14
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/lib/OpenEXRCore/internal_dwa_compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,10 @@ DwaCompressor_uncompress (
uint64_t compressedSize;
const uint8_t* dataPtr;
uint64_t dataLeft;
uint8_t* outBufferEnd;
uint8_t* packedAcBufferEnd;
uint8_t* packedDcBufferEnd;
uint8_t* outBufferEnd;
uint8_t* packedAcBufferEnd;
uint8_t* packedDcBufferEnd;
const uint8_t* dataPtrEnd;
const uint8_t* compressedUnknownBuf;
const uint8_t* compressedAcBuf;
const uint8_t* compressedDcBuf;
Expand Down Expand Up @@ -829,6 +830,7 @@ DwaCompressor_uncompress (
compressedSize = unknownCompressedSize + acCompressedSize +
dcCompressedSize + rleCompressedSize;

dataPtrEnd = inPtr + iSize;
dataPtr = inPtr + headerSize;
dataLeft = iSize - headerSize;

Expand Down Expand Up @@ -909,6 +911,18 @@ DwaCompressor_uncompress (
compressedRleBuf =
compressedDcBuf + (ptrdiff_t) (dcCompressedSize);

if (compressedUnknownBuf >= dataPtrEnd ||
dataPtr > compressedAcBuf ||
compressedAcBuf >= dataPtrEnd ||
dataPtr > compressedDcBuf ||
compressedDcBuf >= dataPtrEnd ||
dataPtr > compressedRleBuf ||
compressedRleBuf >= dataPtrEnd ||
(compressedRleBuf + rleCompressedSize) > dataPtrEnd)
{
return EXR_ERR_CORRUPT_CHUNK;
}

//
// Sanity check that the version is something we expect. Right now,
// we can decode version 0, 1, and 2. v1 adds 'end of block' symbols
Expand Down

0 comments on commit 9d82c14

Please sign in to comment.