You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks good, this implements a check upstream has had since 2018.
I used an AI model to compare this with upstream and noticed two issues and one test suggestion.
Corner cases worth raising
Changelog understates the change.brotlicffi.decompress(stream + junk) and no-limit process(stream + junk) returned the data for the package's entire history and now raise. That's upstream parity and I'd keep it, but HISTORY should say so explicitly rather than only "fixed infinite loops". Note the whole call's output is discarded on the raise, same as upstream.
Post-error state isn't reset. Upstream marks the decoder unhealthy. The PR raises before re-saving _unconsumed_data, so when the raise happens on a second loop iteration (any no-limit call whose initial 5 * len buffer is too small, e.g. compress(b"A"*100) + b"tail") a stale tail stays behind:
1st: Decompression error: trailing data after stream.
unconsumed: b'tail' can_accept: False finished: True
2nd process(b'x'): brotli: decoder process called with data when 'can_accept_more_data()' is False
finish(): b''
Setting self._unconsumed_data = b'' before the raise (or adding a healthy flag) would make the follow-up error consistent. Minor.
Tests. Cheap additions that mirror upstream's test_garbage_appended and test_already_finished: one-shot decompress(stream + b'x'), and process(stream) then process(b'x').
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
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.
Reject trailing data after a complete stream, matching error check of the reference Brotli. This prevents infinite loops while draining the decoder.
Reproducer:
Unpatched brotlicffi loops indefinitely. Patched brotlicffi and reference Brotli raise an error.