Repository navigation
Conversation
A compressed block with an original size of 0 made CompressedInput::Decompress allocate Buffer(0), whose data() is null, and pass it as the LZ4/ZSTD destination; LZ4 does pointer arithmetic on it before it checks the capacity, which is undefined behaviour. A well-formed empty block also left CompressedInput::DoNext without data, so it reported end of stream, and Decompress ignored how many bytes LZ4/ZSTD actually produced, so a block that decoded short exposed a zero-filled tail as data. Decompress empty blocks into a zero-capacity stack target, keep reading blocks until one yields data, and reject output whose length differs from the declared original size.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
CompressedInput::Decompressinbase/compressed.cpptrusts the declared original size in three ways:Buffer(0), whosedata()is null, and passes it to LZ4/ZSTD as the destination. LZ4 does pointer arithmetic on it before checking capacity, which is undefined behaviour (UBSan: "applying non-zero offset to null pointer" inlz4.c).DoNextwith no data, so the stream reports end of input mid-packet.Decompressignores how many bytes LZ4/ZSTD actually produced. A block that decodes to 19 bytes while declaring 20 exposes a zero-filled tail as row data, a silent wrong value.Fix: decompress empty blocks into a zero-capacity stack target, keep reading blocks until one yields data, and throw
CompressionErrorwhen the output length differs from the declared original size, for both LZ4 and ZSTD.Reproducer: a checksum-valid LZ4 block with original size 20 whose payload decodes to 19 bytes, or an LZ4 block with original size 0 and a non-empty payload.
Tests:
CompressedInputCase.SkipsEmptyBlocksandRejectsBlockShorterThanDeclaredOriginalSizefail on master.RejectsEmptyBlockWithNonEmptyContentfails on master in a UBSan build.