Fix error in decompressing RDS files that decompress to more than UINT_MAX bytes #49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When decompressing RDS files that decompress to more than
UINT_MAX
bytes (~4 GB), librdata incorrectly returns an errorCould not open file
.This is caused by truncating assignment of an 8 byte
ssize_t
to a 4 byteuInt
. I fixed this by doing saturating assignment instead. The surrounding decompression loop ensures that larger files can be decompressed (in chunks).C.f https://github.com/madler/zlib/blob/develop/uncompr.c#L58 for a reference implementation that works this way.
I only fixed the bug that I could personally confirm fixed with my changes, the analogous functions using gzip or lzma decompression likely still have similar bugs.
Please consider turning on the
-Wconversion
flag for gcc, as this correctly warns about the assignment that caused this bug. When briefly turning on-Wconversion
, I got a large number of warnings about other lines in the codebase.