fix(gap): iterate 128-bit service UUID lists, skip malformed lengths#226
Merged
Conversation
The Core Spec Vol 3 Part C §11 defines the 128-bit Complete/Incomplete Service UUID AD types as a *list* of UUIDs (length = 1 + 16N), but the parser was treating it as a single UUID. Two regressions resulted: - Multiple 128-bit UUIDs packed into one AD struct (possible in scan responses and BLE-5 extended advertising) returned a single bogus 64-hex-char string instead of two UUIDs. - Malformed payloads (length not 1 + 16N) produced bogus UUID strings (all-zero for short, garbage for long) instead of being skipped. Iterate in 16-byte steps like the 16-/32-bit branches already do, and drop any non-16-byte tail. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #226 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 248 250 +2
Branches 37 39 +2
=========================================
+ Hits 248 250 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes parsing of GAP AD types 0x06/0x07 (128-bit Service UUID lists) to correctly iterate the payload as a list of 16-byte UUIDs and to ignore any trailing malformed remainder, aligning behavior with the Bluetooth Core Spec and the existing 16/32-bit UUID list parsing approach.
Changes:
- Update 128-bit Service UUID AD parsing to iterate in 16-byte chunks and skip trailing non-16-byte tails.
- Add tests covering multiple 128-bit UUIDs in one AD structure and malformed-length handling (too-short and trailing-byte cases).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/bluetooth_data_tools/gap.py |
Parse 128-bit service UUID AD structures as lists of 16-byte UUIDs; ignore trailing remainder bytes. |
tests/test_gap.py |
Add regression tests for multiple 128-bit UUIDs per AD structure and malformed-length payload behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced May 16, 2026
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
The 128-bit Service UUID AD type parser now iterates the payload as a list of UUIDs and discards a non-16-byte tail.
Why
Core Spec Vol 3 Part C §11 defines AD types 0x06 / 0x07 as lists (length = 1 + 16N), not single UUIDs. The parser had been treating them as single, which produced two silent regressions:
How
Replace the single
append()with the samefor i in range(start, end, 16)+if i + 16 <= endpattern the 16-bit and 32-bit branches already use.iis already declaredcython.uintingap.pxd, so no .pxd churn.Testing
pytest tests/ --ignore=tests/benchmarks --ignore=bench→ 69 passed (2 new).SKIP_CYTHON=1→ 58 passed.cythonize→ OK.New tests cover:
Quality Report
Changes: 2 files changed, 52 insertions(+), 1 deletion(-)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline