Skip to content

Commit 2382da3

Browse files
committed
Rewrite defensive code
1 parent eb5ce7b commit 2382da3

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/transform/BWTBlockCodec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ bool BWTBlockCodec::inverse(SliceArray<byte>& input, SliceArray<byte>& output, i
108108
const int chunks = 1 << logNbChunks;
109109
const int headerSize = 1 + chunks * pIndexSize;
110110

111-
if ((input._length < headerSize) || (blockSize < headerSize))
111+
if ((input._length - input._index < headerSize) || (blockSize < headerSize))
112112
return false;
113113

114114
if (chunks != BWT::getBWTChunks(blockSize - headerSize))
@@ -139,7 +139,7 @@ bool BWTBlockCodec::inverse(SliceArray<byte>& input, SliceArray<byte>& output, i
139139
const int blockMode = int(input._array[input._index++]);
140140
const int pIndexSizeBytes = 1 + ((blockMode >> 6) & 0x03);
141141

142-
if (blockSize < pIndexSizeBytes)
142+
if ((blockSize < pIndexSizeBytes) || (input._index + (pIndexSizeBytes - 1) > input._length))
143143
return false;
144144

145145
blockSize -= pIndexSizeBytes;

0 commit comments

Comments
 (0)