Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ Block's lacing header, because the reader unlaces every block up front and a
set of container elements the scan descends into is derived from ebml-go's
element table, and a test fails if they differ. The pre-scan is the first line;
the second is the reader's own bound (go-avkit/avkit v0.17.0,
`container.NewReaderWithLimits`), called with the same clamped limits, whose
`ErrReaderLimit` is answered `video.limit`; a test bypasses the pre-scan and the
reader still refuses. The MP4 sample tables are not pre-scanned: the reader's own bounds apply there.
`container.NewReaderWithLimits`, v0.18.0 for MP4 boxes), called with the same
clamped limits (frames per track and per file, `MaxBoxes`, `MaxDepth`), whose
`ErrReaderLimit` is answered `video.limit`; tests bypass the pre-scan, with a
laced Matroska bomb and an MP4 box flood inside `moov`, and the reader still
refuses. The MP4 sample tables are not pre-scanned: the reader's own bounds apply there.

A panic in the reader or the decoder is answered as a `video.syntax` refusal, in
`Server.Handle` and again at the worker boundary, and the worker keeps serving.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.27.1

require (
github.com/at-wat/ebml-go v0.19.4
github.com/go-avkit/avkit v0.17.0
github.com/go-avkit/avkit v0.18.0
github.com/go-avkit/decode v0.5.4
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/at-wat/ebml-go v0.19.4 h1:6F767ThzH/JqNUsF79PwRFP0pwUF5ALXWJ6pXuiolI8
github.com/at-wat/ebml-go v0.19.4/go.mod h1:wu3fQj+DWo6SOOl9c4yDi+gFs9Oa96Z2B5qxo1OxFYY=
github.com/gen2brain/h265 v0.2.4 h1:JUSbGkRAYZpd7ucCL192yx4ViEo75ZO6OEdm1TQt9qM=
github.com/gen2brain/h265 v0.2.4/go.mod h1:kefpLxLhGpNCUG/q/aabJcD6GqB9Nhet3fNi9xX9Wzw=
github.com/go-avkit/avkit v0.17.0 h1:N4VYofsCswBtQb/Lb7ouhMchvtasKYq6dCMLOMiWrXU=
github.com/go-avkit/avkit v0.17.0/go.mod h1:itL/gmFP0/hIVAQgxn0JTTvlGgY9vi5uL8XI2sOQl/c=
github.com/go-avkit/avkit v0.18.0 h1:7QffdFBr7Scui8aPwy3G/a61rPzAmnjCQZ5xfefaxmE=
github.com/go-avkit/avkit v0.18.0/go.mod h1:itL/gmFP0/hIVAQgxn0JTTvlGgY9vi5uL8XI2sOQl/c=
github.com/go-avkit/bitstream v0.3.1 h1:hZL/9IyRQaXmDd8iEm8ZKT79Tec4pS+HZ+wnQiLaQSc=
github.com/go-avkit/bitstream v0.3.1/go.mod h1:aA50I8nXKyJu6ElfTHM957BRrx5JjgSYUxs++n5VM8o=
github.com/go-avkit/decode v0.5.4 h1:j4jJYR5MHdLzljxAz/nlOScBtLE31OSkzf4jh3G2hXU=
Expand Down
30 changes: 30 additions & 0 deletions serve/lace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package serve
import (
"errors"
"math"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -62,6 +63,35 @@ func TestReaderRefusesLacedBombWithoutThePrescan(t *testing.T) {
}
}

// The reader's box bound (avkit v0.18.0) is the second line for MP4: a flood of
// boxes inside moov, with the pre-scan bypassed, is refused as video.limit by
// the reader with a small allocation. avkit v0.17.0 has no such bound and this
// fails there.
func TestReaderRefusesMP4BoxFloodWithoutThePrescan(t *testing.T) {
var flood []byte
for range 20000 {
flood = append(flood, box("free", nil)...)
}
data := append(append([]byte{}, ftyp...), box("moov", flood)...)
lim := proto.DefaultLimits
lim.MaxBoxes = 1000
if _, _, err := sniff(data, lim); err == nil {
t.Fatal("the pre-scan accepted it: this test would not reach the reader")
}
var before, after runtime.MemStats
runtime.GC()
runtime.ReadMemStats(&before)
_, err := open(data, "mp4", "video/mp4", lim)
runtime.ReadMemStats(&after)
var e *proto.Error
if !errors.As(err, &e) || e.Code != proto.CodeLimit || !strings.Contains(e.Msg, "reader limit") {
t.Errorf("open with the pre-scan bypassed: %v", err)
}
if got := after.TotalAlloc - before.TotalAlloc; got > 1<<20 {
t.Errorf("refusing cost %d bytes of allocation", got)
}
}

func TestBlockFrames(t *testing.T) {
for name, tc := range map[string]struct {
body []byte
Expand Down
1 change: 1 addition & 0 deletions serve/poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func open(data []byte, format, mime string, lim proto.Limits) (*file, error) {
// the pre-scan: the same limits, a request can only lower them
r, err := container.NewReaderWithLimits(data, container.ReaderLimits{
MaxTrackFrames: lim.MaxTrackSamples, MaxFrames: 2 * lim.MaxTrackSamples,
MaxBoxes: lim.MaxBoxes, MaxBoxDepth: lim.MaxDepth,
})
if errors.Is(err, container.ErrReaderLimit) {
return nil, refuse(proto.CodeLimit, "the %s container is over a reader limit: %v", format, err)
Expand Down
Loading