Reject negative read lengths before changing the buffer - #69
Open
OskarEichler wants to merge 1 commit into
Open
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
Reject a negative read length before touching the destination or advancing the read-buffer offset. The current failure can move the offset backwards and expose bytes already consumed.
Reproduction
Focused checks cover three initial offsets, small and arbitrarily large negative integers, both ignore_eof values, unchanged destination contents, zero/positive reads and EOF behavior.
Verification
6cba9756b72eaa5a939b4cb6e032ec1da88b07bd.bundle exec rake test: 30 tests, 66 assertions, zero failures/errors on the baseline and this branch.git diff --checkpass. Supplemental RuboCop Lint has the same 11 pre-existing offenses; no lint-clean claim.Compatibility and limitations
Negative lengths now raise ArgumentError rather than an incidental NoMethodError/RangeError. This is an intentional error-contract correction. Valid lengths and existing destination-append semantics are unchanged; no new coercion rules are introduced.
The patch also applies to installed release 0.3.0, whose runtime file matches the reviewed master. Gem version, dependencies and Ruby >= 2.6 requirement stay unchanged. Only macOS/Ruby 4.0.6 was run locally; other Ruby/OS combinations require upstream CI. No production traffic or external service was used.