MKV parser loops forever on unknown-size or truncated segments

Open
#71 0 comments 0 reactions 0 assignees View on GitHub

@ecdye is already working on this.

Since Nov 27, 2026.

  • #103 by @ecdye — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
macos, swift

Research direction

Start with MKVFileHandler.tryParseElement and the parseTrackEntry loops, then trace MKVTrackParser.extractTrackData and locateCluster. Check how element sizes and EOF are represented, and run the relevant parser tests if available. Done means EOF terminates parsing, unknown sizes and child loops respect their parent bounds, and missing clusters end the loop; an open pull request (#103) is already linked.

Written by the indexing model from the issue text.

Description

bug

MKVFileHandler.tryParseElement never returns nil; at EOF readVINT returns 0, so it yields (0, 0).

In MKVTrackParser.extractTrackData, when locateCluster() returns nil (EOF) the loop does continue, but the offset is still < segmentEndOffset, so it spins forever. This happens for:

  • unknown-size Segments (all-ones VINT, read as 2^56-1), which live/streamed MKVs (OBS, ffmpeg piping) write;
  • truncated files whose Segment size exceeds the file.

The while let … = tryParseElement() loops in parseTrackEntry (both the main one and the CodecPrivate search) are not bounded by the TrackEntry size either, so a TrackEntry missing an expected element runs into the next entry or to EOF and spins on (0, 0).

Fix: make tryParseElement return nil at EOF, treat unknown sizes as "until parent end / EOF", bound child loops by the parent element's end, and break instead of continue when no cluster is found.

Dominant language
Swift
Stars
42
Forks
9
Avg merge
9h 30m
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ecdye/macSubtitleOCR

All issues in ecdye/macSubtitleOCR

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.