fix: handle negative offset in sysread tied READ method#388
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: handle negative offset in sysread tied READ method#388Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
The READ method did not normalize negative offsets before using them, unlike the WRITE method which converts negative offsets to positive and validates bounds. When sysread was called with a negative offset exceeding the buffer length (e.g., sysread($fh, $buf, 10, -100) on a 2-byte buffer), Perl's substr would die instead of producing the proper "Offset outside string" warning with EINVAL. Now matches WRITE behavior: negative offsets are converted to positive (offset = buf_len + offset), and out-of-bounds negatives get a clean warning + EINVAL return. Co-Authored-By: Claude Opus 4.6 <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.
What
Handle negative offsets in the tied
READmethod, matching the existingWRITEbehavior.Why
sysread($fh, $buf, $len, -N)with a negative offset exceeding the buffer length would crash with Perl's substr error instead of producing the proper "Offset outside string" warning withEINVAL— unlikesyswritewhich already handled this correctly.How
Normalize negative offsets to positive (like WRITE already does):
offset = buf_len + offset. If still negative after normalization, warn and returnundefwithEINVAL.Testing
3 new test subtests in
t/sysreadwrite_edge_cases.t:All existing sysread/syswrite tests continue to pass.
🤖 Generated with Claude Code