Skip to content

Fix trun roundtrip correctness - #212

Draft
kixelated wants to merge 1 commit into
mainfrom
codex/fix-trun-roundtrip
Draft

Fix trun roundtrip correctness#212
kixelated wants to merge 1 commit into
mainfrom
codex/fix-trun-roundtrip

Conversation

@kixelated

Copy link
Copy Markdown
Owner

Fixes #186

Summary

  • preserve the valid first_sample_flags layout and reject mixed per-sample field presence that cannot be encoded without changing inherited tfhd semantics
  • decode version 0 composition offsets as unsigned and version 1 offsets as signed, widening TrunEntry::cts to Option<i64> so both ranges are representable
  • select the compatible trun version when encoding composition offsets and reject incompatible or out-of-range values
  • reject malformed trun boxes that set both first_sample_flags and sample_flags

Root cause and impact

The decoder and encoder did not use the trun version when reading composition offsets, and partially populated per-sample fields could be silently omitted or replaced with zero. This could lose key-frame flags or change values inherited from tfhd defaults during a decode/encode roundtrip.

The public TrunEntry::cts field changes from Option<i32> to Option<i64> to cover the complete v0 unsigned and v1 signed value ranges.

Validation

  • cargo test (240 unit tests and 3 doc tests)
  • cargo check --all-features
  • cargo clippy --all-targets --all-features -- -D warnings
  • 11 targeted trun regression tests

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.

trun: first_sample_flags lost on re-encode; mixed per-sample fields silently dropped; v0 cts read as signed

1 participant