Skip to content

libusb/test: scan trailing hex bytes forward (Coverity false positive) - #846

Merged
Youw merged 1 commit into
masterfrom
clarify-report-parser-bounds
Nov 9, 2026
Merged

Youw merged 1 commit into
masterfrom
clarify-report-parser-bounds

Conversation

@Youw

@Youw Youw commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

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:

  • Claude Fable 5.1 review: no blocking code findings.
  • All 26 parser/fixture tests passed with GCC and Clang sanitizers; 2 million randomized old/new comparisons found no differences.
  • Retained Windows, macOS and Linux captures merged successfully: 7 + 6 + 10 = 23 translation units. Submission retry passed.
  • Hosted Coverity snapshot 219325, November 9, 2026, matches commit 9f703e9: CID 1706117 eliminated, zero newly detected and zero outstanding findings.
  • All active CI checks passed.

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).

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
@Youw
Youw merged commit 418d62a into master Nov 9, 2026
35 of 36 checks passed
@Youw
Youw deleted the clarify-report-parser-bounds branch November 9, 2026 12:21
@mcuee mcuee added the Test Related to built-in test (not hidtest) label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Test Related to built-in test (not hidtest)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants