Skip to content

[codex] Avoid ranged octet string index overflow#422

Merged
jadamcrain merged 1 commit into
mainfrom
chore/ranged-octet-max-index
May 10, 2026
Merged

[codex] Avoid ranged octet string index overflow#422
jadamcrain merged 1 commit into
mainfrom
chore/ranged-octet-max-index

Conversation

@jadamcrain
Copy link
Copy Markdown
Member

@jadamcrain jadamcrain commented May 10, 2026

Summary

Avoid a debug-build integer overflow when iterating ranged octet string data whose final index is u16::MAX.

The iterator already captured the correct index before incrementing, so release builds wrapped after the last item and still produced the expected output. This change makes the increment explicit and consistent with the generic ranged iterator by using a saturating increment.

It is not a production (release) issue.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the safety of the DNP3 parser by replacing a standard increment with saturating_add in the RangedBytesIterator, preventing potential overflow panics when the index reaches its maximum value. A corresponding test case was added to verify parsing at the u16::MAX boundary. The reviewer noted that for full consistency and safety, the Index trait implementation for u16 should also be updated to use saturating arithmetic, as it currently still uses a standard increment that could trigger panics in debug builds.

Comment thread dnp3/src/app/parse/bytes.rs
@jadamcrain jadamcrain marked this pull request as ready for review May 10, 2026 14:19
@jadamcrain jadamcrain merged commit 52358f0 into main May 10, 2026
31 checks passed
@jadamcrain jadamcrain deleted the chore/ranged-octet-max-index branch May 10, 2026 14:20
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.

1 participant