PGS fragmented ODS handling is wrong

Open Beginner friendly
#77 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
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
swift

Research direction

Start by reading PGS.parseNextSubtitle and ODS.parseODS, named in the issue. Check how the sequence flag controls continuation handling and where fragment dimensions and RLE data offsets are read. Done means objects spanning three or more fragments decode correctly without invalidRLE, while fragment appending stops at the last-in-sequence bit.

Written by the indexing model from the issue text.

Description

bug

In PGS.parseNextSubtitle, after appending a continuation ODS fragment:

offset += segmentLength
if buffer[offset - 10] != 0x40 { break }

offset - 10 points 10 bytes before the end of the segment, into RLE data, not at the sequence flag (segment start + 3). Both branches then fall through to the same return, so an object split over 3+ fragments is returned after the second.

In ODS.parseODS, a middle fragment (sequence flag 0x00) is treated like a first fragment: it re-reads width/height from pixel data and skips 7 bytes of RLE (dataOffset = offset + 11).

Result: large objects decode wrong or throw invalidRLE, which aborts the run.

Fix: read the flag at the segment start, only take dimensions from a fragment with the first-in-sequence bit (0x80), use offset + 4 for any fragment without it, and keep appending until the last-in-sequence bit (0x40).

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.