Skip to content

Commit b0cacc3

Browse files
authored
More unbounded input fixes. Re-fix for px20 (#64)
1 parent c2c5491 commit b0cacc3

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

.github/workflows/ubuntu-20.04-make.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ jobs:
1515
run: sudo apt-get update && sudo apt-get install -y build-essential make
1616
- name: make
1717
run: make -f Makefile.unix EXTRA_CFLAGS=-Werror
18+
- name: test
19+
run: ./obj/test

src/CompressDecompressor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void CompressDecompressor::decompressImpl(Buffer &rawData,bool verify)
8686
size_t prevCodePos=inputStream.getOffset();
8787

8888
uint32_t firstCode{readBits(codeBits)};
89-
LZWDecoder decoder{1U<<_maxBits,_hasBlocks?257U:256U,69001U,firstCode};
89+
LZWDecoder decoder{1U<<_maxBits,_hasBlocks?257U:256U,8192U,firstCode};
9090
decoder.write(firstCode,false,writeByte);
9191

9292
// This is actually surprising for a compressor
@@ -101,7 +101,8 @@ void CompressDecompressor::decompressImpl(Buffer &rawData,bool verify)
101101
auto reset=[&]()
102102
{
103103
bitReader.reset(0,0);
104-
inputStream.setOffset(prevCodePos+codeBits);
104+
prevCodePos+=codeBits;
105+
inputStream.setOffset(prevCodePos);
105106
codeCounter=0;
106107
};
107108

src/MMCMPDecompressor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ MMCMPDecompressor::MMCMPDecompressor(const Buffer &packedData,bool exactSizeKnow
3333
_blocks=packedData.readLE16(12U);
3434
_blocksOffset=packedData.readLE32(18U);
3535
_rawSize=packedData.readLE32(14U);
36+
if (_rawSize>getMaxRawSize())
37+
throw InvalidFormatError();
3638
if (OverflowCheck::sum(_blocksOffset,uint32_t(_blocks)*4U)>packedData.size())
3739
throw InvalidFormatError();
3840

src/PPDecompressor.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ void PPDecompressor::findKeyRound(BackwardInputStream &inputStream,LSBBitReader<
318318
bitReader.readBitsBE32(count);
319319
};
320320

321-
for (;;)
321+
uint32_t foundIter=0;
322+
// TODO: Random constant. For decompression/keyfinding bombs
323+
while (foundIter<1024)
322324
{
323325
// this is the checkpoint. Hardly ideal, but best we can do without co-routines
324326
inputOffset=uint32_t(inputStream.getOffset());
@@ -364,10 +366,12 @@ void PPDecompressor::findKeyRound(BackwardInputStream &inputStream,LSBBitReader<
364366
count=modeIndex+2;
365367
distance=readBits(_modeTable[modeIndex])+1;
366368
}
367-
if (outputPosition+count+distance>_rawSize || count>outputPosition)
369+
if (outputPosition+distance>_rawSize || count>outputPosition)
368370
failed=true;
369371
if (failed) break;
370372
outputPosition-=count;
373+
374+
if (keyMask==0xffff'ffffU) foundIter++;
371375
}
372376
if (failed) return;
373377
// If not all bits are resolved, that is bad

0 commit comments

Comments
 (0)