Repository navigation
fix(playback): bound the Cues a Matroska keyframe index reads - #2492
Conversation
A crafted Matroska file could make one keyframe-index read allocate about ten times its Cues element, up to roughly 1 GiB at the old 64 MiB limit. The reader grew a slice of cue points one append at a time and built maps of every cue time and cluster position before checking any cluster. Count the video cue points first and allocate the sorted cue times and cluster positions once, look keyframes up by binary search instead of in maps, and lower the Cues limit to 16 MiB. FFmpeg writes a video cue point in 17 to 24 bytes, so 16 MiB covers every frame of 8 hours at 24 fps or 3 hours at 60 fps. A read now costs at most about three times the Cues size. Closes #2487 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
The playback playlist can change for Matroska files whose Cues exceed 16 MiB: Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Silo-Server#2492 split cuePoints into a counting walkCuePoints and a single allocation. Take that structure; the walk keeps this branch's rule that a video cue with a CueReference or a nonzero CueCodecState makes the Cues incomplete. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Closes #2487
Related issue: N/A
Validation tasks: none
A crafted Matroska file could make one keyframe-index read allocate about ten times the size of its Cues element: around 250 MiB for 16 MiB of Cues, and close to 1 GiB at the old 64 MiB limit, even when the read then failed. Anyone who can add a file to a library could trigger that each time playback loads the file's keyframe index, and #2484 adds a second caller for seek previews. This change keeps every read to at most about three times the Cues size and lowers the Cues limit to 16 MiB. Normal files read the same as before.
The cost came from the parser itself. It grew the list of cue points one append at a time, and before reading any cluster it built a map of every cue time and another of every cluster position. The background full check built two more maps of the same size. Found in review of #2484.
Approach
cuePointsnow walks the Cues twice: once to count the video cue points, then again to fill sorted, deduplicated lists of cue times and cluster positions, each allocated once. The coverage check and the full check look keyframes up in the sorted times by binary search instead of in maps. Which clusters get sampled, what counts as covered, and every error stay the same.maxCuesSizedrops from 64 MiB to 16 MiB. FFmpeg writes a video cue point in 17 to 24 bytes, so 16 MiB holds about 700,000 points: every frame of 8 hours at 24 fps, or of 3 hours at 60 fps. A film with a keyframe every few seconds has Cues well under a megabyte. A file over the limit gets the existing size error, and playback uses FFmpeg's own playlist, as it already does for files without Cues. A rare case could change: very long high-frame-rate all-intra files, or files whose Cues also index many other tracks.Only
internal/playback/keyframeschanges. There are no client, API, or jellycompat changes.Validation
go test ./internal/playback/...passes, including the tests that compare the index with ffprobe and with FFmpeg's HLS cuts.make lint-changed,go build ./...,gofmt -l .,go vet ./..., andmake verify-local-pathspass.make test-gopasses except twointernal/mediasampletests that run real FFmpeg (TestRunStatsWithRealFFmpeg,TestRunSheetsOpenGOPHEVCWithRealFFmpeg). They fail the same way with main's keyframes code on the same machine, so the local FFmpeg build is the cause.Evidence: https://evidence.siloserver.org/r/silo-server/issue-2487/
Evidence
No user-visible change. The evidence page linked under Validation holds the test results.
Risks
A Matroska file with more than 16 MiB of Cues now falls back to FFmpeg's playlist instead of the planned keyframe playlist. Normal library files have Cues far below that.
Checklist
AI Disclosure
-1cluster positions while main skips every negative one. The change now skips every negative position. It agreed with the 16 MiB limit and pointed out that cues for other tracks make real Cues larger than a video-only count, which the Risks section covers. A background adversarial review by Codex (gpt-6.1-sol) of 4f156cb found nothing to report: the playback tests passed, and 40,000 differential comparisons against the previous parser matched.🤖 Generated with Claude Code
Note
Bound the Cues a Matroska keyframe index reads to 16 MiB
Lowers the maximum accepted Matroska
Cueselement size from 64 MiB to 16 MiB in matroska.go, so memory use stays bounded when reading a keyframe index.cuePointsnow counts cues in a first pass, allocates its result slices once at final capacity, and returns sorted, duplicate-free cue times and cluster positions.Cuesbyte size.Cueselements between 16 MiB and 64 MiB are now rejected;cuePointsandcheckCueCoveragesignatures changed from cue-point structs to parallel slices.Macroscope summarized 4f156cb.