VobSub parser reads outside the buffer on malformed input

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

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
macos, swift
Domain
backend, security

Research direction

Start by reading VobSubParser.readSubFrame and follow how filepos, PES lengths, nextOffset, and the derived RLE and control sizes are used. Check each buffer access and derived range against the available buffer and next offset, then verify malformed subtitle data fails only that subtitle without terminating the process.

Written by the indexing model from the issue text.

Description

bug

VobSubParser.readSubFrame reads with loadUnaligned(fromByteOffset:) and buffer[...] on an UnsafeRawBufferPointer at offsets taken from the file with no bounds checks. Those are only checked in debug builds, so in release a malformed .sub/.idx (filepos near the end, bogus PES length, etc.) reads out of bounds.

Negative derived sizes also build reversed ranges, which trap even in release:

  • rleSize = relativeControlOffset - 4 can be negative, making controlSize negative and buffer[offset ..< offset + bytesToCopy] reversed.
  • rleFragmentSize = nextPSOffset - offset - difference can be negative.

Fix: bounds-check every read against the buffer (and nextOffset), validate derived sizes, and fail the single subtitle instead of the process.

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.