opus_tags: validate Ogg serial, page sequence, and OpusTags flags (OGG-RETAG-STREAM-CHECK) #386

Open
github-bot wants to merge 1 commit from github-bot/gh-386 into main AGit
Owner

@⁠tahffo68hk-hash on GitHub · 2026-11-24 04:17 UTC · original
tahffo68hk-hash:fix/ogg-retag-stream-check → main · +57 −6 · 2 files · 1 commits · open

Claimed in the coordination issue as: OGG-RETAG-STREAM-CHECK

Problem

tools/opus_tags.py validates Ogg page CRCs in retag() before rewriting page 1, but did not check:

  1. Logical bitstream serial number consistency across page 0, page 1 (OpusTags), and all subsequent audio pages.
  2. Contiguous Ogg page sequence numbers (page 0 = 0, page 1 = 1, audio pages = 2, 3, ...).
  3. Header type flags on the OpusTags page (such as the continuation flag 0x01, or unexpected BOS/EOS flags 0x02/0x04 that retag() would silently overwrite with 0x00).

Structurally malformed Ogg Opus inputs with valid page CRCs were therefore accepted and rewritten.

Fix

  • In retag(), verify page 0 has sequence number 0, every page shares the same logical bitstream serial number, subsequent audio pages have contiguous sequence numbers starting at 2, and page 1 does not carry the continuation (0x01) or BOS/EOS (0x02/0x04) flags.
  • Add synthetic regression tests in tests/test_opus_tags.py (TestRetag.test_retag_rejects_serial_mismatch_sequence_gap_and_continuation_flags).

Verification

  • Commands:
    • python -I tests/test_opus_tags.py -v TestRetag TestPacket -> 7/7 OK
    • python -I tests/test_opus_tags_dialogue_conflicts.py -> 6/6 OK
    • (Note: test_cli_reports_incomplete_directory_discovery in test_opus_tags.py has a pre-existing Windows path-repr failure tracked in #312 and was left untouched.)
  • Environment: Windows 11, Python 3.13.12 (no game files, CPU-only).
  • AI-assisted: Yes (Antigravity).
中文翻译

在协调帖 #14 中认领的 ID:OGG-RETAG-STREAM-CHECK

问题描述

tools/opus_tags.py 中的 retag() 在改写第 1 页前校验了各页的 Ogg CRC,但遗漏了以下结构校验:

  1. 第 0 页、第 1 页(OpusTags)及后续所有音频页的逻辑比特流序列号(serial)一致性。
  2. Ogg 页序号连续性(第 0 页为 0、第 1 页为 1、后续音频页为 2, 3, ...)。
  3. OpusTags 页的页头标志位(如续页标记 0x01,或会被 retag() 静默覆写为 0x00 的 BOS/EOS 标志 0x02/0x04)。

因此 CRC 正确但结构异常的 Ogg Opus 文件会被接受并改写。

修复方案

  • 在 retag() 中校验第 0 页序号为 0、所有页面逻辑流序列号一致、后续音频页序号从 2 开始连续递增,且第 1 页不带续页标记(0x01)或 BOS/EOS 标志(0x02/0x04)。
  • 在 tests/test_opus_tags.py 中补充合成回归测试(覆盖 6 类结构异常)。

验证结果

  • tests/test_opus_tags.py -v TestRetag TestPacket:7/7 通过。
  • tests/test_opus_tags_dialogue_conflicts.py:6/6 通过。
  • (注:test_opus_tags.py 中 test_cli_reports_incomplete_directory_discovery 在 Windows 上存在 #312 已跟踪的既有路径转义失败,未改动。)
  • 环境:Windows 11,Python 3.13.12(无游戏文件,纯 CPU 测试)。
  • AI 辅助:是(Antigravity)。
**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 04:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/386) `tahffo68hk-hash:fix/ogg-retag-stream-check` → `main` · +57 −6 · 2 files · 1 commits · open Claimed in the coordination issue as: `OGG-RETAG-STREAM-CHECK` ## Problem `tools/opus_tags.py` validates Ogg page CRCs in `retag()` before rewriting page 1, but did not check: 1. Logical bitstream serial number consistency across page 0, page 1 (`OpusTags`), and all subsequent audio pages. 2. Contiguous Ogg page sequence numbers (page 0 = `0`, page 1 = `1`, audio pages = `2, 3, ...`). 3. Header type flags on the `OpusTags` page (such as the continuation flag `0x01`, or unexpected BOS/EOS flags `0x02`/`0x04` that `retag()` would silently overwrite with `0x00`). Structurally malformed Ogg Opus inputs with valid page CRCs were therefore accepted and rewritten. ## Fix - In `retag()`, verify page 0 has sequence number `0`, every page shares the same logical bitstream serial number, subsequent audio pages have contiguous sequence numbers starting at `2`, and page 1 does not carry the continuation (`0x01`) or BOS/EOS (`0x02`/`0x04`) flags. - Add synthetic regression tests in `tests/test_opus_tags.py` (`TestRetag.test_retag_rejects_serial_mismatch_sequence_gap_and_continuation_flags`). ## Verification - Commands: - `python -I tests/test_opus_tags.py -v TestRetag TestPacket` -> 7/7 OK - `python -I tests/test_opus_tags_dialogue_conflicts.py` -> 6/6 OK - (Note: `test_cli_reports_incomplete_directory_discovery` in `test_opus_tags.py` has a pre-existing Windows path-repr failure tracked in #312 and was left untouched.) - Environment: Windows 11, Python 3.13.12 (no game files, CPU-only). - AI-assisted: Yes (Antigravity). <details> <summary>中文翻译</summary> 在协调帖 #14 中认领的 ID:`OGG-RETAG-STREAM-CHECK` ## 问题描述 `tools/opus_tags.py` 中的 `retag()` 在改写第 1 页前校验了各页的 Ogg CRC,但遗漏了以下结构校验: 1. 第 0 页、第 1 页(`OpusTags`)及后续所有音频页的逻辑比特流序列号(serial)一致性。 2. Ogg 页序号连续性(第 0 页为 `0`、第 1 页为 `1`、后续音频页为 `2, 3, ...`)。 3. `OpusTags` 页的页头标志位(如续页标记 `0x01`,或会被 `retag()` 静默覆写为 `0x00` 的 BOS/EOS 标志 `0x02`/`0x04`)。 因此 CRC 正确但结构异常的 Ogg Opus 文件会被接受并改写。 ## 修复方案 - 在 `retag()` 中校验第 0 页序号为 `0`、所有页面逻辑流序列号一致、后续音频页序号从 `2` 开始连续递增,且第 1 页不带续页标记(`0x01`)或 BOS/EOS 标志(`0x02`/`0x04`)。 - 在 `tests/test_opus_tags.py` 中补充合成回归测试(覆盖 6 类结构异常)。 ## 验证结果 - `tests/test_opus_tags.py -v TestRetag TestPacket`:7/7 通过。 - `tests/test_opus_tags_dialogue_conflicts.py`:6/6 通过。 - (注:`test_opus_tags.py` 中 `test_cli_reports_incomplete_directory_discovery` 在 Windows 上存在 #312 已跟踪的既有路径转义失败,未改动。) - 环境:Windows 11,Python 3.13.12(无游戏文件,纯 CPU 测试)。 - AI 辅助:是(Antigravity)。 </details>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:57:05 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/386/head:github-bot/gh-386'
git switch 'github-bot/gh-386'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-386'
git switch 'github-bot/gh-386'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-386'
git switch 'github-bot/gh-386'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-386'
git switch 'main'
git merge --squash 'github-bot/gh-386'
git switch 'main'
git merge --ff-only 'github-bot/gh-386'
git switch 'main'
git merge 'github-bot/gh-386'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.