Skip to content

container: Matroska lacing unlaces without a frame bound (about 13 KiB allocated per input byte) #120

Closed

Description

@tannevaled

container.NewReader unlaces every Matroska SimpleBlock up front (matroska_read.go:450-480, 495-506), and no bound on the number of frames is applied before that. A caller's MaxTrackSamples is only checked later, by consumers such as decode.PosterFrame. A probe never reaches that check.

A 7-byte SimpleBlock with fixed lacing and lace count byte 0xFF unlaces into 256 empty frames, and ebml-go accepts it (unlacer.go:113-117). Measured natively through go-avkit/worker's Handle (probe, default limits), with avkit v0.16.0:

File Blocks Allocated
7.2 KB 1,000 95 MiB
70 KB 10,000 925 MiB (HeapSys 555 MiB, GOMEMLIMIT=512MiB)

The growth is linear, about 13 KiB allocated per input byte. A 1.8 MB file reaches about 14 GiB, beyond the 4 GiB address space of a wasm worker.

Wanted: the reader enforces a frame (sample) budget while unlacing, with a refusal error, before it allocates. Either take a limit from the caller, or have a default that the caller can only lower. Add a bomb test that asserts the REFUSAL under GOMEMLIMIT, and a fuzz seed for a maximal lace count. This is the same family as #113 (MP4 box count). Callers' pre-scans (go-avkit/worker scanEBML) are being fixed to count lace frames meanwhile, but the bound belongs in the reader.

Found by the independent security review of go-avkit/worker#1.

Refs #89

Prior art: priorart "matroska lacing unbounded frames memory" at 2026-11-14 13:19 CET reported prior art; checked: priorart hits were Matroska feature PRs and the MP4 box-count bound #113 (same family, different format); none bounds lace frames

Activity

  1. tannevaled commented on Nov 14, 2026

    @tannevaled
    ContributorAuthor

    The same gap exists in go-slides' own pre-scan: see go-slides/slides#106, whose fix is pending. go-avkit/worker v0.1.0 already counts lace frames in its pre-scan. The reader-level bound is #121.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions