Skip to content

Fix crash on empty zstd response body #411

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

Merged
merged 5 commits into from
Mar 16, 2025
Merged

Conversation

blyxxyz
Copy link
Collaborator

@blyxxyz blyxxyz commented Mar 5, 2025

Fixes a panic for xh head https://httpbin.dev/zstd.

ZstdDecoder::new() returns a Result. We used to panic on this, but it needs to be a Read error instead, so we can suppress the error for an empty input the way we do for other decoders.

Our existing approach couldn't handle this, so I ended up refactoring the system. I think it's cleaner now, though still weird.

We now also preserve the original decoder error instead of .to_string()ing it, or strip it completely if there was an I/O error. That should improve the error reporting.

This PR also contains a fix for the binary data detection: in certain circumstances, like an invalid streaming brotli response, it would print the "binary data" note instead of an error.

Resolves #409.

blyxxyz added 3 commits March 5, 2025 20:52
Fixes a panic for `xh head https://httpbin.dev/zstd`.

`ZstdDecoder::new()` returns a `Result`. We used to panic on this, but
it needs to be a `Read` error instead, so we can suppress the error
for an empty input the way we do for other decoders.

Our existing approach couldn't handle this, so I ended up refactoring
the system. I think it's cleaner now, though still weird.

We now also preserve the original decoder error instead of
`.to_string()`ing it, or strip it completely if there was an I/O
error. That should improve the error reporting.
We used to use `ErrorKind::InvalidData` to communicate binary data
that should not be shown in the terminal but that one can actually
happen in other cases as well. brotli decoding uses that ErrorKind,
and we now use it for all decompressors.

So an invalid brotli response would under certain circumstances render
as "NOTE: binary data not shown in terminal".

We can use our own error type to track this properly.
Copy link
Owner

@ducaale ducaale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@ducaale ducaale merged commit 24afadb into ducaale:master Mar 16, 2025
9 checks passed
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

Successfully merging this pull request may close these issues.

panic with compressed response from server
2 participants