Repository navigation
libusb/test: scan trailing hex bytes forward (Coverity false positive) - #846
Merged
Merged
Conversation
parse_trailing_hex_bytes() found the trailing run of two-digit hex tokens by walking backwards from token_count and reading tokens[first_hex_token - 1]. The loop guard and the 128-token limit already keep that index in range, but Coverity reports it as an INTEGER_OVERFLOW (CID 1706117). This is a false positive. Instead, scan forward and record where the current hex run starts: each non-hex token moves the start past itself. That way every array index is bounded directly by the loop condition. The behaviour does not change: the same 128-token limit, the same bytes appended in the same order, the same return values, and the same partial-append-then-fail behaviour when the destination buffer is full. Add --self-test cases for metadata before the hex run, lines with no trailing hex, blank lines, mixed-case hex, buffer overflow, and both sides of the 128-token limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: claude-code:claude-opus-5-5
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.
Coverity CID 1706117 (INTEGER_OVERFLOW) was a false positive in the trailing-hex parser. Scan tokens forward so every array index is directly bounded, preserving parsing behavior, the 128-token limit and partial writes on output overflow. Extend the existing self-tests for metadata, empty/non-hex input, mixed case, buffer limits and token boundaries.
Validation:
Related to #845.
Related to #841.
Assisted-by: claude-code:claude-opus-5-5
Assisted-by: claude-code:claude-fable-5-1
Assisted-by: Codex:GPT-6
Generated by Claude Code (Claude Opus 5.5); reviewed by Claude Fable 5.1 and Codex (GPT-6).