Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small error in decoding streams with first_byte not 0 and total sequence_len 0 #83

Open
Progxy opened this issue Feb 17, 2025 · 0 comments

Comments

@Progxy
Copy link

Progxy commented Feb 17, 2025

When trying to decode the following file from the official zstd repo zeroSeq_2B.zst
Here can be seen how they actually do it zstd_repo.

The idea is to first extract the first byte, then check it to see if it is greater than "0x7F" and then after the usual read of the extra bytes, check if the result sequence_len is actually 0.
In the case of the aforementioned example it requires to read an extra byte (as first_byte = 128), and then the read byte is 0, so the result is sequence_len = 0, and the decoding should conclude with copying the content of the literals into the frame buffer.

Here is the result of the operation at the moment (at commit 48ac3e4):

cargo run --bin zstd -- ./golden-decompression/zeroSeq_2B.zst -d -c
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/zstd ./golden-decompression/zeroSeq_2B.zst -d -c`
File: ./golden-decompression/zeroSeq_2B.zst
Found Raw literalssection with regenerated size: 13, and compressed size: None
Slice for literals: 13
thread 'main' panicked at src/bin/zstd.rs:86:22:
called `Result::unwrap()` on an `Err` value: FailedToReadBlockBody(DecompressBlockError(SequencesHeaderParseError(NotEnoughBytes { need_at_least: 3, got: 2 })))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The fix should be pretty straightforward, as is just a matter of the order of the if-checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant