Repository navigation
[FIX] Process each RCWT input as its own stream - #2395
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In raising this pull request, I confirm the following (please check boxes):
Reason for this PR:
Sanity check:
Repro instructions:
Use the 153-byte RCWT sample from #2342/#2347 as
a.rcwtand a copy with different text asb.rcwt, then runccextractor a.rcwt b.rcwt --out=srt -o out.srt. On master only the first file's captions are written and the log saysProcessing 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 runsrcwt_loop()on it. The existing per-filefts_globaloffset 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()freeddec_ctx->xds_ctxwithout clearing it, a double free on the second pass (ASan); it now usesfreep()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_encoderleak; 30 varied single-file samples are unchanged.