Return nil for items outside buffer bounds in undersized packets#2685
Merged
Return nil for items outside buffer bounds in undersized packets#2685
Conversation
When a packet with ALLOW_SHORT receives an undersized buffer, items that are completely outside the buffer bounds now return nil/None instead of 0. Previously, undersized buffers were padded with zeros which caused out-of-bounds items to return 0. Changes: - Structure no longer resizes buffer when short_buffer_allowed is true - BinaryAccessor.read_item checks bounds before reading and returns nil/None for items outside the buffer - Added item_within_buffer_bounds? method to check if item fits in buffer - Updated comments in accessor classes to reflect new behavior Fixes #2463 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2685 +/- ##
==========================================
- Coverage 79.22% 79.22% -0.01%
==========================================
Files 670 670
Lines 54178 54192 +14
Branches 734 734
==========================================
+ Hits 42923 42933 +10
- Misses 11175 11179 +4
Partials 80 80
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
Author
|
You still have to opt into this behavior with "ALLOW_SHORT" for binary packets. |
ryan-pratt
reviewed
Jan 5, 2026
ryanmelt
requested changes
Jan 9, 2026
Address PR review comment by moving the bounds checking logic into the existing low-level read functions instead of having a separate item_within_buffer_bounds? check. This eliminates duplicate bounds checking and keeps the check in the C code for better performance. Changes: - C code returns nil instead of raising on bounds error - Ruby/Python read methods return nil on bounds failure - Added bounds check to read_array to return nil for undersized buffers - Removed item_within_buffer_bounds method and its call from read_item - Removed unnecessary resize_buffer call in structure files - Updated tests to expect nil instead of errors for out-of-bounds reads Co-Authored-By: Claude Opus 4.5 <[email protected]>
…ackets Add nil guards to prevent errors when items return nil for being outside buffer bounds in undersized packets: - Add nil guard in check_limits to skip limits checking for nil values - Add nil guard in apply_format_string_and_units to return nil early - Add nil guard in polynomial_conversion (Ruby, C extension, and Python) - Add nil guard in segmented_polynomial_conversion (Ruby and Python) Update tests to use properly sized buffers or expect nil for out-of-bounds items. Co-Authored-By: Claude Opus 4.5 <[email protected]>
ryan-pratt
approved these changes
Jan 16, 2026
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.
When a packet with ALLOW_SHORT receives an undersized buffer, items that are completely outside the buffer bounds now return nil/None instead of 0. Previously, undersized buffers were padded with zeros which caused out-of-bounds items to return 0.
Changes:
Fixes #2463
🤖 Generated with Claude Code
NOTE: I accidentally made this PR against main so we do not want to merge until we merge the v7.0.0 branch. Let me know if you want me to rebase against v7.0.0.