Skip to content

[FIX] Stop reading past the end of the credits text in WebVTT, SAMI and SMPTE-TT - #2400

Open
Deepak-negi11 wants to merge 1 commit into
CCExtractor:masterfrom
Deepak-negi11:fix/credits-read-past-end
Open

Deepak-negi11 wants to merge 1 commit into
CCExtractor:masterfrom
Deepak-negi11:fix/credits-read-past-end

Conversation

@Deepak-negi11

@Deepak-negi11 Deepak-negi11 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:

Sample: Closed Caption EIA.ts from https://streams.videolan.org/streams/ts/ (CC/wabc-4pm-ota.clip1.ts also works). Build with AddressSanitizer (-fsanitize=address) to see the error.

Command Before After
ccextractor --out=webvtt --startcreditstext 'Alpha\nBravo\nCharlie' sample.ts AddressSanitizer: heap-buffer-overflow, crash Works
same with --out=sami heap-buffer-overflow, crash Works
same with --out=smptett heap-buffer-overflow, crash Works

Problem

These writers turn every \n in the credits text (2 characters) into a line break (1 character), so the result is shorter than the input. But they then read the result back using the input's length, so they read past the end of the data. This is the same bug you described for SSA in the #2316 review.

Fix

Read back only what was written. This is the same two-line fix #2128 made in the SRT writer. SSA has the same bug, but #2316 rewrites that function, so I didn't touch it.

Testing

  • AddressSanitizer runs in the table above, on two samples: crashes before, clean after.
  • clang-format is clean.

Notes:

  • The SAMI and SMPTE-TT functions also write every normal subtitle, not just credits. Their output doesn't change: without a literal \n in the text, both lengths are equal.
  • The pos_r < len - 1 change isn't a bug fix (at the last character, string[pos_r + 1] is the string's ending zero). It just keeps the code the same as the SRT writer after Fix potential out-of-bounds access in write_stringz_as_srt_to_output #2128.

Copilot AI balanced review requested due to automatic review settings October 18, 2026 17:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…nd SMPTE-TT

write_stringz_as_webvtt/sami/smptett unescape "\n" into a NUL, which
writes fewer bytes (pos_w) than the input length (len), but then read
the segments back while begin < unescaped + len. With
--startcreditstext 'Alpha\nBravo\nCharlie' this reads past the written
data and off the end of the buffer (AddressSanitizer:
heap-buffer-overflow in encode_line). Bound the read-back by pos_w.

The pos_r < len - 1 check in the escape test is not a fix (at the last
character string[pos_r + 1] is the terminating NUL); it keeps the code
the same as ccx_encoders_srt.c after CCExtractor#2128.

The SAMI and SMPTE-TT functions also write every normal text subtitle.
Their output doesn't change: without a literal "\n", pos_w equals len.
The SSA writer has the same bug; it is left to CCExtractor#2316, which rewrites
that function.
@Deepak-negi11
Deepak-negi11 force-pushed the fix/credits-read-past-end branch from 547f7cc to a54f6c7 Compare October 18, 2026 18:15
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.

2 participants