Skip to content

feat: WebM output, corruption-tolerant reader, and parser hardening#1

Merged
gravity-zero merged 3 commits into
masterfrom
webm-reader-hardening
Jun 2, 2026
Merged

feat: WebM output, corruption-tolerant reader, and parser hardening#1
gravity-zero merged 3 commits into
masterfrom
webm-reader-hardening

Conversation

@gravity-zero

Copy link
Copy Markdown
Owner

WebM:

  • mkv.ValidateWebM / IsWebMCodec / WebMDocTypeVersion + writer.WriteWebM and writer.NewWebMStreamWriter (webm DocType, codec allowlist, codec init-data checks)
  • ops.RemuxToWebM: remux a source into a complete .webm, dropping non-WebM elements
  • surfaced through the matroska facade

Reader robustness:

  • recover from zeroed/corrupted body regions by resyncing to the next valid, validated cluster instead of erroring out
  • bound chapter/tag/lacing recursion and cap every element allocation so crafted input cannot OOM or stack-overflow; guard divide-by-zero on TimecodeScale=0
  • FuzzRead + FuzzBlockReader and corruption/lacing regression tests (incl. saved crasher)
  • align the streaming parser with the seekable one: ContentEncodings/HeaderStripping, nested SimpleTags + TagBinary, sub-chapters (with parity tests)

Streaming / performance:

  • stream Mux/Merge/AddTrack via a bounded k-way timecode merge (constant memory)
  • stack-buffer ReadVINT, buffered Demux and RemuxToWebM output, incremental large-element reads

Also: facade forwards ...Options on all ops, doc example fixes, dead-code moved out of prod.

WebM:
- mkv.ValidateWebM / IsWebMCodec / WebMDocTypeVersion + writer.WriteWebM and
  writer.NewWebMStreamWriter (webm DocType, codec allowlist, codec init-data checks)
- ops.RemuxToWebM: remux a source into a complete .webm, dropping non-WebM elements
- surfaced through the matroska facade

Reader robustness:
- recover from zeroed/corrupted body regions by resyncing to the next valid,
  validated cluster instead of erroring out
- bound chapter/tag/lacing recursion and cap every element allocation so crafted
  input cannot OOM or stack-overflow; guard divide-by-zero on TimecodeScale=0
- FuzzRead + FuzzBlockReader and corruption/lacing regression tests (incl. saved crasher)
- align the streaming parser with the seekable one: ContentEncodings/HeaderStripping,
  nested SimpleTags + TagBinary, sub-chapters (with parity tests)

Streaming / performance:
- stream Mux/Merge/AddTrack via a bounded k-way timecode merge (constant memory)
- stack-buffer ReadVINT, buffered Demux and RemuxToWebM output, incremental large-element reads

Also: facade forwards ...Options on all ops, doc example fixes, dead-code moved out of prod.
@codecov-commenter

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

…ce risk

- ReadElementID rejects VINTs wider than 4 octets instead of truncating into
  uint32 — a 5+ octet ID was silently corrupted (EBML conformance)
- reader caps the total in-memory metadata per parse (attachments, codec-private,
  binary tags); the 512 MiB per-element cap did not bound a file with many large
  metadata elements
- EditInPlace documents that it is not crash-safe (use EditMetadata for atomic
  writes) and fsyncs after the in-place write
The CI lint failure was an unused vorbisInit var, not a config issue.

- webm_test.go: use vorbisInit (adds a Vorbis validation case)
- blocks.go: lift loop condition into the for statement (staticcheck)
- pin golangci-lint to v1.64.8 (golangci-lint-action@v6 resolves "latest" to the
  latest v1.x; pinning keeps lint reproducible)
@gravity-zero gravity-zero merged commit 44a16f0 into master Jun 2, 2026
10 checks passed
@gravity-zero gravity-zero deleted the webm-reader-hardening branch June 2, 2026 19:35
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