fix(gap): include trailing 2-byte AD struct in parse bounds#221
Merged
Conversation
The AD-struct parsing loop used `offset + 2 < total_length`, which is one byte too strict: a trailing minimum-AD struct ([length=1][type], 2 bytes, zero data) was silently skipped instead of entered. Use `<=` so the final 2-byte struct is bounds-checked and processed by the loop body like every other AD struct.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #221 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 248 248
Branches 37 37
=========================================
Hits 248 248 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bdraco
approved these changes
May 15, 2026
bluetoothbot
added a commit
that referenced
this pull request
May 15, 2026
…h regression - Broad fuzz loop stays unseeded so each CI run explores new payloads, prints the seed (overridable via `FUZZ_SEED`) so failures reproduce locally. Drops the per-iteration `print` that spammed 1000 lines. - Only `_uncached_parse_advertisement_data` is fuzzed; the cached wrappers are no-op LRU shells around it. - Adds `test_gap_fuzzer_truncated_length_does_not_crash`, a seeded regression check for the off-by-one fixed in #221 — feeds payloads whose declared length overruns the buffer and asserts the parser rejects the struct without raising. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
What
Fix off-by-one in
_uncached_parse_advertisement_bytesso a trailing minimum-AD struct ([length=1][type], 2 bytes) is no longer silently skipped.Why
The loop guard
offset + 2 < total_lengthexcluded the case where exactly 2 bytes (a valid minimum AD header) remained — those bytes were dropped without ever entering the loop body or the existing invalid-AD bounds checks.How
Changed the loop condition to
offset + 2 <= total_length. The body's existingend > total_length/end - start <= 0checks correctly handle the zero-data case. Pure off-by-one — no surrounding cleanup.Testing
test_parse_advertisement_data_trailing_minimum_ad_structfeeds a payload ending in a 2-byte AD struct, asserts preceding manufacturer data still parses, and verifies the trailing struct is now entered (debug log fires).Quality Report
Changes: 2 files changed, 16 insertions(+), 1 deletion(-)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline