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

Detect truncated frames to avoid infinite loop #47

Merged
merged 3 commits into from
May 19, 2024

Conversation

nhz2
Copy link
Member

@nhz2 nhz2 commented May 19, 2024

Fixes #24

The streaming decompression function will only return zero when a frame is fully decoded and flushed out.
If the return value is not an error it will be less than or equal to the number of bytes left in the frame that haven't been read yet.
If process is called with input.size==0 there is no more data left to decompress.

So if there is no more data left to decompress, but zstd is asking for more data, then the frame is truncated, and error should be returned.
Ref: facebook/zstd#340 (comment) facebook/zstd#1109 https://github.com/facebook/zstd/blob/dev/examples/streaming_decompression.c

Copy link

codecov bot commented May 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 31.84%. Comparing base (4c799fe) to head (a62e8c9).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #47      +/-   ##
==========================================
+ Coverage   30.98%   31.84%   +0.86%     
==========================================
  Files           5        5              
  Lines         510      515       +5     
==========================================
+ Hits          158      164       +6     
+ Misses        352      351       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nhz2 nhz2 marked this pull request as ready for review May 19, 2024 00:51
@nhz2 nhz2 requested review from jrevels and mkitti May 19, 2024 01:09
Copy link
Member

@mkitti mkitti 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 to me. Thanks.

@mkitti mkitti merged commit 4b8aecd into master May 19, 2024
8 checks passed
@mkitti mkitti deleted the nz/fix-decompressor-infinite-loop branch May 19, 2024 20:44
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.

transcode(ZstdDecompressor, UInt8[]) hangs indefinitely
2 participants