[codex] Avoid ranged octet string index overflow#422
Merged
Conversation
There was a problem hiding this comment.
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.
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.
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.