Skip to content

fix(hang): refuse malformed H.264 codec fields (backport #6847) - #9256

Merged
kixelated merged 1 commit into
releasefrom
fix/hang-h264-codec-backport
Nov 21, 2026
Merged

kixelated merged 1 commit into
releasefrom
fix/hang-h264-codec-backport

Conversation

@kixelated

@kixelated kixelated commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

hang's H264::from_str on release checks the profile field's length in bytes and then slices it at byte offsets 2 and 4. A non-ASCII character in a remote catalog's avc1/avc3 codec string (e.g. avc1.4Ψ01e) splits a UTF-8 character and panics Catalog::from_slice / from_str in any consumer that parses it (GHSA-gj9x-g66f-6j3p). The fix landed on main in moq-dev/moq#6847 but never reached a release: published hang 0.21.24 still panics.

Approach

Port moq-dev/moq#6847 unchanged: the field must be six ASCII hex digits. moq-dev/moq#7035's later rework changes the catalog API, so it stays on main.

The other catalog codec parsers on release don't slice at unchecked byte offsets: H.265 slices at [1..] only after an ASCII first byte.

Impact

  • No public API or wire change. A malformed avc1/avc3 codec string is now Error::InvalidCodec instead of a panic; ships as a hang patch with the next release.

Validation

  • The ported malformed_hex_fields_are_invalid test panics at h264.rs:55:46 without the check, the reporter's location, and passes with it.
  • The reporter's catalog through Catalog::<()>::from_slice, run as a temporary test: now Err(Json("invalid codec at line 1 column 54")).
  • cargo test -p hang (120 pass) and nix develop -c just check origin/release pass.

Caused by

  • No single PR: the byte-length check is as old as the H.264 codec-string parser.

Alternatives

  • Only add part.is_ascii(), the reporter's patch. Porting main's stricter hex check keeps release and main the same.

Follow-ups

None.

Models

Size: XS
Implementer: Claude Code, claude-opus-5-5, unknown effort

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: a2bf49b

  • Base: origin/release at 381b802

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

  • Reviewer: Codex, gpt-6.1-sol, medium effort

  • Session: 01a1fb8b-77eb-75b3-9003-ce3da27df9a9, round 1

  • Score: 10/10, Source review found that ASCII hexadecimal validation prevents UTF-8 slicing panics while preserving valid H.264 codec strings, with regression coverage for both prefixes and every field boundary; tests were not run as instructed.

  • Rounds: 2; first round 2 (medium 2); findings 0: fixed 0, refuted 0, open 0

  • Findings: none

A non-ASCII byte in an avc1/avc3 profile field sliced the codec string
inside a UTF-8 character and panicked the catalog parser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 21, 2026 00:40

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Approach: sound — rejects non-hex profile fields before the byte-offset slicing, so a non-ASCII character can no longer split a UTF-8 boundary and panic.

Reviewed changes

Reviewed the single commit against release.

  • Hex validation in H264::from_str — the field must now be exactly six bytes and all ASCII hex digits, which makes the [0..2], [2..4] and [4..6] slices safe. Malformed input returns Error::InvalidCodec.
  • Regression test — malformed_hex_fields_are_invalid covers avc1 and avc3 with non-ASCII characters at each field boundary, a leading + and non-hex letters.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@kixelated
kixelated enabled auto-merge November 21, 2026 00:57
@kixelated
kixelated merged commit 17afa89 into release Nov 21, 2026
34 of 37 checks passed
@kixelated
kixelated deleted the fix/hang-h264-codec-backport branch November 21, 2026 01:01
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.

1 participant