]> git.ipfire.org Git - thirdparty/zstd.git/commit
Simplify 32-bit long offsets decoding logic
authorNick Terrell <terrelln@fb.com>
Mon, 30 Jan 2023 19:15:15 +0000 (11:15 -0800)
committerNick Terrell <nickrterrell@gmail.com>
Mon, 30 Jan 2023 20:21:42 +0000 (12:21 -0800)
commit2f74507bbd0e8aca907a2842a311cc24ec815cf2
tree91ce6916b0d47bb59e1a7c150aeb99a2dda8cbd9
parent00176638e35a41d7a9d098e75731c89d5e5a8a40
Simplify 32-bit long offsets decoding logic

The previous code had an issue when `bitsConsumed == 32` it would read 0
bits for the `ofBits` read, which violates the precondition of
`BIT_readBitsFast()`. This can happen when the stream is corrupted.

Fix thie issue by always reading the maximum possible number of extra
bits. I've measured neutral decoding performance, likely because this
branch is unlikely, but this should be faster anyways. And if not, it is
only 32-bit decoding, so performance isn't as critical.

Credit to OSS-Fuzz
lib/common/zstd_internal.h
lib/decompress/zstd_decompress_block.c