Skip to content

Fix record offsets when parsing a list of PAC records - #993

Merged
zxzxwu merged 1 commit into
google:mainfrom
kwy404:fix-pac-record-list-parsing
Sep 29, 2026
Merged

zxzxwu merged 1 commit into
google:mainfrom
kwy404:fix-pac-record-list-parsing

Conversation

@kwy404

@kwy404 kwy404 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

PacRecord.list_from_bytes moved to the next record by adding len(bytes(record)), which is the length of the re-serialized record, not the number of bytes that were parsed. CodecSpecificCapabilities.__bytes__ always writes all five LTVs, but Supported_Audio_Channel_Counts and Supported_Max_Codec_Frames_Per_SDU are optional and default to 1 when absent (BAP 4.3.1). A record without them is 6 bytes shorter than its re-serialized form, so every record after it in a Sink or Source PAC value (PACS Table 3.2 and 3.4) was parsed from the wrong offset. This affects PublishedAudioCapabilitiesServiceProxy.sink_pac and source_pac, used for example by apps/device_info.py.

This adds PacRecord.parse_from_bytes(data, offset), following the CodingFormat.parse_from_bytes pattern, which returns the offset after the record, and uses it in list_from_bytes. from_bytes keeps its behavior.

Added test_pac_record_list in tests/profiles/bap_test.py, which parses two LC3 records that only carry the mandatory capabilities; it fails before the change (the second record is decoded starting 6 bytes too late and raises UnboundLocalError) and passes after. Ran the tests/profiles suites, plus black, ruff, pylint and mypy on the touched files.

@zxzxwu zxzxwu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@zxzxwu
zxzxwu merged commit f5b780f into google:main Sep 29, 2026
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants