Skip to content

[FIX] Process each RCWT input as its own stream - #2395

Merged
cfsmp3 merged 2 commits into
masterfrom
fix/rcwt-concat
Oct 18, 2026
Merged

cfsmp3 merged 2 commits into
masterfrom
fix/rcwt-concat

Conversation

@cfsmp3

@cfsmp3 cfsmp3 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

In raising this pull request, I confirm the following (please check boxes):

Reason for this PR:

  • This PR adds new functionality.
  • This PR fixes a bug that I have personally experienced or that a real user has reported and for which a sample exists.
  • This PR is porting code from C to Rust.

Sanity check:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • If the PR adds new functionality, I've added it to the changelog. If it's just a bug fix, I have NOT added it to the changelog.
  • I am NOT adding new C code unless it's to fix an existing, reproducible bug.

Repro instructions:

Use the 153-byte RCWT sample from #2342/#2347 as a.rcwt and a copy with different text as b.rcwt, then run ccextractor a.rcwt b.rcwt --out=srt -o out.srt. On master only the first file's captions are written and the log says Processing of b.rcwt 1 ended prematurely 0 < 153, please send bug report.


Stacked on #2394 (based on its branch; the stale-buffer replay fixed there also made the second RCWT pass re-read the first file). Merge #2394 first.

With several RCWT inputs, binary concatenation let rcwt_loop() read straight from the end of one file into the next. Each RCWT file starts with its own 11-byte header, which was then parsed as a caption data header, so the second file's captions were never extracted.

  • rcwt_loop() turns binary concatenation off for its own reads (restored on return), so it stops at the end of each file; start_ccx() then opens the next file and runs rcwt_loop() on it. The existing per-file fts_global offset places each file's captions after the previous file's — each RCWT file has its own time base starting near 0, so without it they would overlap.
  • rcwt_loop() freed dec_ctx->xds_ctx without clearing it, a double free on the second pass (ASan); it now uses freep() and creates a new XDS context when a later pass finds none.

Verified: both input orders give all six cues (file 1 at 1–7 s, file 2 at 8.4–14.4 s) with no "ended prematurely" warning, also in the C-only build; ASan shows only the known 32-byte init_encoder leak; 30 varied single-file samples are unchanged.

init_file_buffer(), called by every open(), rewound filebuffer_pos to
0 but kept bytesinbuffer when the buffer already existed. Everything
the previous input file left in the buffer - normally fully consumed -
thus counted as unread data of the newly opened file and was replayed.

With several inputs and binary concatenation this re-fed the start of
the previous file (its stream-detection bytes, up to 1 MB) into the
stream at every file boundary: split recordings produced repeated and
mistimed captions after the join, or aborted. The same replay made a
second RCWT input re-read the first.

Reset bytesinbuffer as well, in both the C and the Rust version.
Whatever the buffer holds at that point belongs to the previous file.
With several RCWT inputs, binary concatenation let rcwt_loop() read
straight from the end of one file into the next. Each RCWT file starts
with its own 11-byte header, which was then parsed as a caption data
header: the second file's captions were never extracted, and
switch_to_next_file() reported "ended prematurely 0 < 153".

Turn binary concatenation off for rcwt_loop()'s reads (restored on
return), so it stops at the end of each file. start_ccx() then opens
the next file and runs rcwt_loop() on it, and the existing per-file
fts_global offset places its captions after the previous file's
instead of on top of them.

rcwt_loop() frees dec_ctx->xds_ctx when it ends without clearing the
pointer, which became a double free on the second pass: clear it with
freep() and create a new XDS context when a later pass finds none.
Base automatically changed from fix/concat-timing to master October 18, 2026 04:50
@cfsmp3
cfsmp3 merged commit 4425c04 into master Oct 18, 2026
46 of 48 checks passed
@cfsmp3
cfsmp3 deleted the fix/rcwt-concat branch October 18, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant