[PR #1855] fix(raw): Fix premature EOF and timing overflow in raw_loop #2622

Open
opened 2026-01-29 17:23:08 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/CCExtractor/ccextractor/pull/1855

State: closed
Merged: Yes


Summary

Fixes #1565 - CCExtractor stops processing raw caption files at exactly 9:43:00 (2MB).

Root causes found and fixed:

  1. Premature EOF bug: After processing the first chunk (BUFSIZE = ~2MB), data->len was never reset to 0. On the next iteration, general_get_more_data() calculated want = BUFSIZE - data->len = 0 and returned EOF immediately.

    • Fix: Added data->len = 0 after processing each chunk and changed loop condition from while (data->len) to while (1) with explicit breaks.
  2. 32-bit integer overflow: The calculation cb_field1 * 1001 / 30 * (MPEG_CLOCK_FREQ / 1000) overflowed when cb_field1 was large (>1 million). For example, 34,989,487 * 90 = 3,149,053,830 exceeds the 32-bit signed integer max (2,147,483,647).

    • Fix: Cast cb_field1 to LLONG before the multiplication.
  3. Timing initialization: Raw mode needs proper initialization (min_pts=0, sync_pts=0, pts_set=MinPtsSet) for the Rust timing code to calculate fts_now correctly.

Test plan

Tested with sample files from issue #1565:

  • DTV3.raw: Now processes to 17:59:56 (was stopping at 9:43)
  • DTV4.raw: Now processes to 14:00:00 (was stopping at 9:43)
  • DTV5.raw: Now processes to 13:19:59 (was stopping at 9:43)
  • All Rust tests pass (286 tests)

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1855 **State:** closed **Merged:** Yes --- ## Summary Fixes #1565 - CCExtractor stops processing raw caption files at exactly 9:43:00 (2MB). ### Root causes found and fixed: 1. **Premature EOF bug**: After processing the first chunk (BUFSIZE = ~2MB), `data->len` was never reset to 0. On the next iteration, `general_get_more_data()` calculated `want = BUFSIZE - data->len = 0` and returned EOF immediately. - **Fix**: Added `data->len = 0` after processing each chunk and changed loop condition from `while (data->len)` to `while (1)` with explicit breaks. 2. **32-bit integer overflow**: The calculation `cb_field1 * 1001 / 30 * (MPEG_CLOCK_FREQ / 1000)` overflowed when `cb_field1` was large (>1 million). For example, `34,989,487 * 90 = 3,149,053,830` exceeds the 32-bit signed integer max (2,147,483,647). - **Fix**: Cast `cb_field1` to `LLONG` before the multiplication. 3. **Timing initialization**: Raw mode needs proper initialization (`min_pts=0`, `sync_pts=0`, `pts_set=MinPtsSet`) for the Rust timing code to calculate `fts_now` correctly. ## Test plan Tested with sample files from issue #1565: - [x] DTV3.raw: Now processes to 17:59:56 (was stopping at 9:43) - [x] DTV4.raw: Now processes to 14:00:00 (was stopping at 9:43) - [x] DTV5.raw: Now processes to 13:19:59 (was stopping at 9:43) - [x] All Rust tests pass (286 tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claunia added the pull-request label 2026-01-29 17:23:08 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2622