Skip to content

awc_opus: clear error for packets over 255 Ogg segments (AWC-OPUS-OGG-SEGMENT-LIMIT) - #6336

Merged
shayderrr merged 1 commit into
ItsNotRexed:mainfrom
cloph-dsp:fix/awc-opus-ogg-segment-limit
Nov 23, 2026
Merged

shayderrr merged 1 commit into
ItsNotRexed:mainfrom
cloph-dsp:fix/awc-opus-ogg-segment-limit

Conversation

@cloph-dsp

Copy link
Copy Markdown
Contributor

Claim: AWC-OPUS-OGG-SEGMENT-LIMIT (claimed in #6214).

ogg_page() built the lacing table without checking the Ogg limit of 255 segments per page. A malformed AWC bank with a u16 Opus packet length of 65025 bytes or more hit struct.error: 'B' format requires 0 <= number <= 255 with no context. It now raises ValueError("packet needs more than 255 Ogg segments").

Added tests/test_awc_opus.py::OggCrcTest::test_page_segment_limit, which checks the largest valid single-packet page (65024 bytes: 254 full segments plus a partial one) and the first invalid length (65025, which needs an extra zero segment).

No game files, extracted assets or logs are included.

AI-assisted (Hy4 flash).

Testing (Windows, Python 3.14.6):

GPU/driver: N/A - pure Python tool change, no GPU code paths.

@Kev-Ball

Copy link
Copy Markdown

Two boundary details from checking a14674c8 on CachyOS:

  • The limit applies to the whole page. I passed write_ogg_opus two synthetic packets, 3 and 65,024 bytes. Each fits a page by itself (1 and 255 lacing entries), and libopus decoded each to 960 samples per channel. Together they reached the new guard with 256 entries and raised “packet needs more than 255 Ogg segments.” A page-level diagnostic such as “page needs 256 Ogg segments (maximum 255)” covers both the single-packet regression and this case.
  • The malformed-bank example in the description takes a different path through the CLI. Both plain and music streams use opus_packets(), which reads length-prefixed packets inside 2,048-byte subblocks. With a synthetic subblock, a declared length of 2,046 returned one packet, while 2,047 and 65,025 each returned zero. The guard is directly reproducible at the Ogg writer API. Describing the regression at that boundary would help readers reproduce it.

For the two-packet control I used the three-byte Opus silence packet and opus_packet_pad to construct the longer packet. CPU only, AI-assisted.

@shayderrr shayderrr 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.

Review

Reviewed change in PR #6336: awc_opus: clear error for packets over 255 Ogg segments (AWC-OPUS-OGG-SEGMENT-LIMIT).

Scope: tests/test_awc_opus.py, tools/awc_opus.py
Diff: +9 / -0 across 2 file(s).

The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.

Reviewed by shayderrr via batch review.

@shayderrr

Copy link
Copy Markdown
Collaborator

Thanks @cloph-dsp - I went through this change and the diff around tests/test_awc_opus.py. The change is tight, the rationale matches the code, and nothing here needs another pass from my side. Approved and squash-merging it into main now. Nice work.

@shayderrr
shayderrr merged commit b54dbd6 into ItsNotRexed:main Nov 23, 2026
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.

3 participants