[LOW] Prevent Unpacker#skip_nil from replaying nil indefinitely - #41
Open
OskarEichler wants to merge 1 commit into
Open
[LOW] Prevent Unpacker#skip_nil from replaying nil indefinitely#41OskarEichler wants to merge 1 commit into
OskarEichler wants to merge 1 commit into
Conversation
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.
Summary
CBOR::Unpacker#skip_nilconsumes the nil byte from the input buffer but leaves it cached as the current head byte. Every laterskip_nilcall therefore returnstruefor the same value, and the nextreadalso replays nil instead of returning the following object.This resets the cached head after a successful skip so the stream advances exactly once.
Reproduction
0.5.10.3 prints
[true, true, true]and thennil. A caller usingwhile unpacker.skip_nilnever reaches the following object. This branch prints[true, false, false]and then1.Verification
read, preserving the intended peek behavior.EOFError.rake compile,gem build cbor.gemspec, andgit diff --checkpass.No tests were changed because this repository asks contributors not to add or modify tests.
Scope and limitations
The affected entry point is the low-level streaming
Unpacker#skip_nilAPI. The infinite loop requires a caller to repeatskip_nil; it remains interruptible Ruby code, unlike a native-extension loop. NormalCBOR.decodedoes not use this method.Breaking changes
skip_nilnow consumes a nil exactly once, as its name and documentation imply. Code that relied on repeatedly observing the same skipped nil will behave differently; valid stream decoding is otherwise unchanged.