Skip to content

Commit da2e675

Browse files
committed
Fix a potential integer overflow when decompressing big blocks in parallel
1 parent 0431777 commit da2e675

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/io/CompressedInputStream.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ istream& CompressedInputStream::read(char* data, streamsize length)
465465

466466
while (remaining > 0) {
467467
// Limit to number of available bytes in current buffer
468-
const int lenChunk = min(remaining, min(_available, _bufferThreshold - _buffers[_bufferId]->_index));
468+
const int lenChunk = min(remaining, int(min(_available, int64(_bufferThreshold - _buffers[_bufferId]->_index))));
469469

470470
if (lenChunk > 0) {
471471
// Process a chunk of in-buffer data. No access to bitstream required
@@ -500,7 +500,7 @@ istream& CompressedInputStream::read(char* data, streamsize length)
500500
return *this;
501501
}
502502

503-
int CompressedInputStream::processBlock()
503+
int64 CompressedInputStream::processBlock()
504504
{
505505
readHeader();
506506

@@ -511,7 +511,7 @@ int CompressedInputStream::processBlock()
511511
try {
512512
// Add a padding area to manage any block temporarily expanded
513513
const int blkSize = max(_blockSize + EXTRA_BUFFER_SIZE, _blockSize + (_blockSize >> 4));
514-
int decoded = 0;
514+
int64 decoded = 0;
515515
int nbTasks = _jobs;
516516
int jobsPerTask[MAX_CONCURRENCY];
517517

src/io/CompressedInputStream.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ namespace kanzi
206206
int _nbInputBlocks;
207207
int _jobs;
208208
int _bufferThreshold;
209-
int _available; // decoded not consumed bytes
209+
int64 _available; // decoded not consumed bytes
210210
int64 _outputSize;
211211
XXHash32* _hasher32;
212212
XXHash64* _hasher64;
@@ -226,7 +226,7 @@ namespace kanzi
226226
ThreadPool* _pool;
227227
#endif
228228

229-
int processBlock();
229+
int64 processBlock();
230230

231231
int _get(int inc);
232232

0 commit comments

Comments
 (0)