-
Notifications
You must be signed in to change notification settings - Fork 63
Return nil for items outside buffer bounds in undersized packets #2685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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 <noreply@anthropic.com>
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:
|
|
You still have to opt into this behavior with "ALLOW_SHORT" for binary packets. |
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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>
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.