Skip to content

Commit 68b14b8

Browse files
committed
The decompressor incorrectly uses a block size that includes the BWT indexes to validate the number of chunks. In case the initial block size is slightlty lower than BLOCK_SIZE_THRESHOLD1 (256), the incorrect block size can be greater than 256, then the computed number of chunks is incorrect, leading to a decompression failure
1 parent 51f9b1b commit 68b14b8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/transform/BWTBlockCodec.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,14 @@ bool BWTBlockCodec::inverse(SliceArray<byte>& input, SliceArray<byte>& output, i
105105
const uint logNbChunks = uint(mode >> 2) & 0x07;
106106
const int pIndexSize = (int(mode) & 0x03) + 1;
107107
const int chunks = 1 << logNbChunks;
108-
109-
if (chunks != BWT::getBWTChunks(blockSize))
110-
return false;
111-
112108
const int headerSize = 1 + chunks * pIndexSize;
113109

114110
if ((input._length < headerSize) || (blockSize < headerSize))
115111
return false;
116112

113+
if (chunks != BWT::getBWTChunks(blockSize - headerSize))
114+
return false;
115+
117116
// Read header
118117
for (int i = 0; i < chunks; i++) {
119118
int shift = (pIndexSize - 1) << 3;
@@ -135,7 +134,7 @@ bool BWTBlockCodec::inverse(SliceArray<byte>& input, SliceArray<byte>& output, i
135134
const int chunks = BWT::getBWTChunks(blockSize);
136135

137136
for (int i = 0; i < chunks; i++) {
138-
// Read block header (mode + primary index). See top of header file for format
137+
// Read block header (mode + primary index)
139138
const int blockMode = int(input._array[input._index++]);
140139
const int pIndexSizeBytes = 1 + ((blockMode >> 6) & 0x03);
141140

0 commit comments

Comments
 (0)