Skip to content

Commit

Permalink
Fix possible decompression loop when dealing with corrupt data
Browse files Browse the repository at this point in the history
Summary: We're seeing a case where a file with known data corruption issues can block record decoding, triggering an infinite loop, where no data is read from disk, but no data is extracted from the decompressor either. This case is now caught by this new check.

Reviewed By: maxouellet

Differential Revision: D50828445

fbshipit-source-id: cf8ba13a4e58e1b88282eab66c8bc9913a5f05ce
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Oct 31, 2023
1 parent 937b3c0 commit ab3f966
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vrs/RecordReaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ int CompressedRecordReader::read(
uint32_t& outReadSize) {
outReadSize = 0;
do {
bool readData = false;
if (decompressor_.getRemainingCompressedDataBufferSize() == 0 && remainingDiskBytes_ > 0) {
size_t targetReadSize = (knownNeedSize - outReadSize >= remainingUncompressedSize_)
? remainingDiskBytes_
Expand All @@ -100,6 +101,7 @@ int CompressedRecordReader::read(
if (error != 0) {
return error;
}
readData = true;
}
uint32_t decompressedSize = 0;
int error = decompressor_.decompress(
Expand All @@ -109,6 +111,9 @@ int CompressedRecordReader::read(
if (error != 0) {
return error;
}
if (!readData && decompressedSize == 0) {
return NOT_ENOUGH_DATA;
}
} while (outReadSize < destSize);
return 0;
}
Expand Down

0 comments on commit ab3f966

Please sign in to comment.