Fix Zstd.decompress dropping all but the first of concatenated frames#139
Open
Watson1978 wants to merge 1 commit into
Open
Fix Zstd.decompress dropping all but the first of concatenated frames#139Watson1978 wants to merge 1 commit into
Watson1978 wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #138
Problem
Zstd.decompressonly decoded the first frame of concatenated zstd frames and silently dropped the rest. The zstd format explicitly supports frame concatenation (e.g.cat a.zst b.zst | zstd -dyields the concatenation of both), andZSTD_decompress/ZSTD_decompressStreamdecode all frames, so the previous behavior diverged from the format.Cause
rb_decompressreturned immediately after decoding the first data frame instead of looping back to process the remaining input. (The skippable-frame branch already advancedoffand continued the loop; the data-frame branch did not.)Fix
decode_one_framenow reports how many input bytes it consumed (the finalZSTD_inBuffer.pos) via a newsize_t* consumedout-parameter, so the caller can advance past the frame. The existingdecompress_bufferedcaller is updated to passNULL.rb_decompressscans the whole input, accumulating every frame's output:DCtxis created once and reused across frames (decode_one_framealready resets the session viaZSTD_reset_session_only), and freed after the loop.rb_str_cat, so the common single-frame case stays zero-copy.offis advanced by the consumed byte count and the loop continues; aconsumed == 0guard prevents an infinite loop.rb_raise, andRB_GC_GUARD(input_value)are preserved.Out of scope:
dict:/kwargs handling, streaming, and skippable-frame behavior are unchanged. The public API signature and return type ofZstd.decompressare unchanged.Verification
bundle exec rake specpasses (17 examples, 0 failures), with no new compiler warnings. New regression specs cover concatenated frames:a + bdecompresses to"Hello, World!"a + b + c) is fully concatenated🤖 Generated with Claude Code