MKV TrackEntry parsing force unwraps and misreads track numbers

Open Beginner friendly
#72 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
swift
Domain
backend, data

Research direction

Start with MKVTrackParser.parseTrackEntry and trace how TrackNumber and Language elements are read and associated within one TrackEntry. Check the parser’s existing tests for element ordering and multi-byte unsigned values. Done means empty or multi-byte TrackNumber values are handled without traps, and Language is associated with its track regardless of child order.

Written by the indexing model from the issue text.

Description

bug

In MKVTrackParser.parseTrackEntry:

  • languages[trackNumber!] = language traps if the Language element comes before TrackNumber. EBML does not guarantee child order.
  • trackNumber = Int((fileHandle.readData(ofLength: Int(elementSize)).first)!) traps on an empty element and only reads the first byte, so track numbers stored in more than one byte are wrong.

Fix: read TrackNumber as an unsigned integer of elementSize bytes, record the language after the entry is fully parsed, and remove the force unwraps.

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.