Repository navigation
legacy/v0.5: fix streaming regression from the wrap history fix - #4816
Open
ManoharPaturi wants to merge 1 commit into
Open
ManoharPaturi wants to merge 1 commit into
ManoharPaturi wants to merge 1 commit into
Conversation
The fix for facebook#4553 preserved the last windowSize bytes with a memmove when the streaming output buffer wraps. Two configurations were missed: when outEnd equals windowSize at the wrap, the preserved window fills the whole buffer, leaving no room for the next block, so the streaming decoder rejects valid frames with dstSize_tooSmall; when outEnd exceeds windowSize, the memmove relocates history that the decoder's vBase and dictEnd pointer arithmetic still addresses at its old location, so external dictionary match sources read the wrong bytes. Frames crossing a full window boundary now fail to stream at all: a frame produced by v0.5.1 itself, decodable by the one-shot API and by every streaming decoder before that fix, returns dstSize_tooSmall. Size the output buffer at windowSize plus one block, as the v0.6 and v0.7 decoders already do, and return the wrap to a plain reset: the buffer now only wraps once outStart has moved a full window past its start, at which point every offset within the window resolves before the reset point, so the reset drops nothing the next block can reference. This keeps the facebook#4553 case fixed (the wrap no longer happens mid window) and restores the frames the memmove broke. The new test frames cover both shapes: a block that fills the window exactly, and the sub-window shape from facebook#4553.
This branch has not been deployed
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.
The fix for #4553 (commit 3a3c506) preserved the last windowSize bytes with a memmove when the streaming output buffer wraps. Two configurations were missed.
When outEnd equals windowSize at the wrap, the preserved window fills the whole buffer, leaving no room for the next block, so the streaming decoder rejects valid frames with dstSize_tooSmall.
When outEnd exceeds windowSize, the memmove relocates history that the decoder still addresses through its vBase and dictEnd pointer arithmetic, which assumes history bytes stay in place, so external dictionary match sources read from the wrong location.
The first case is now the common one: any v0.5 frame whose streaming decode crosses a full window boundary fails, because the wrap first fires exactly when the buffer is full. A frame produced by the v0.5.1 command line itself, decodable by the one shot API and by every streaming decoder before that commit, now returns:
The v0.6 and v0.7 decoders already solve the underlying problem by sizing the output buffer at windowSize plus one block and keeping the wrap as a plain reset. The buffer then only wraps once outStart has moved a full window past its start, at which point every offset within the window resolves before the reset point, so the reset drops nothing a later block can reference. This change brings the v0.5 decoder to that design: the wrap no longer happens mid window, which keeps #4553 fixed, and the frames the memmove broke decode again.
Test evidence, all through the public API on unfixed dev versus this change:
issue #4553 reproducer: passes before, passes after
frame from v0.5.1, 1.2 MB decoded across several windows: dstSize_tooSmall before, matches the one shot decoder after
crafted frame, block filling the window exactly: dstSize_tooSmall before, matches after
crafted frame in the #4553 shape: passes before, passes after
The two crafted frames are added to tests/legacy.c, gated on ZSTD_LEGACY_SUPPORT at or below 5, and the existing legacy tests pass at every level from 1 to 7.