Skip to content

Conversation

@jmthomas
Copy link
Member

@jmthomas jmthomas commented Dec 26, 2025

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

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.

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
Copy link

codecov bot commented Dec 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.22%. Comparing base (0df95af) to head (bcf232b).
⚠️ Report is 2 commits behind head on main.

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              
Flag Coverage Δ
python 80.98% <ø> (-0.02%) ⬇️
ruby-api 84.19% <ø> (+0.04%) ⬆️
ruby-backend 82.21% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jmthomas
Copy link
Member Author

jmthomas commented Dec 26, 2025

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>
@jmthomas jmthomas requested a review from ryanmelt January 9, 2026 20:30
jmthomas and others added 3 commits January 13, 2026 20:40
…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>
@jmthomas jmthomas requested a review from ryan-pratt January 15, 2026 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change behavior of undersized packets to return null for items outside of packet

4 participants