Skip to content

[FIX] NUL-terminate mode/info strings in add_cc_sub_text - #2331

Merged
cfsmp3 merged 3 commits into
CCExtractor:masterfrom
NaitikVerma6776:fix/add_cc_sub_text-nul-terminate
Sep 5, 2026
Merged

[FIX] NUL-terminate mode/info strings in add_cc_sub_text#2331
cfsmp3 merged 3 commits into
CCExtractor:masterfrom
NaitikVerma6776:fix/add_cc_sub_text-nul-terminate

Conversation

@NaitikVerma6776

@NaitikVerma6776 NaitikVerma6776 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #2330

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

Reason for this PR:

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:

This is a C string bug in add_cc_sub_text(), not a single-file caption extraction failure. No video sample is attached because the defect is in how mode / info are copied.

  1. struct cc_subtitle has char mode[5] and char info[4].
  2. Callers pass 4-character modes: "ISDB" (ccx_decoders_isdb.c) and "BURN" (hardsubx_decoder.c).
  3. Old code used strncpy(..., 4). When the source is exactly 4 characters, strncpy does not write '\0'.
  4. Transcript output then uses strcmp(sub->mode, "TLT") and "%s" on sub->mode (ccx_encoders_transcript.c), which requires a terminator.
  5. "TLT" (3 characters) was already terminated by strncpy. The first subtitle can also look fine if the struct was calloc'd (the extra byte is already 0). Later nodes use malloc and can leave mode[4] as garbage.

How to confirm from source: search for add_cc_sub_text(..., "ISDB" / "BURN" and the old strncpy(..., 4) on master vs this branch.


Summary

add_cc_sub_text() now copies info and mode with sizeof(field) - 1 and always writes a terminating '\0'.

That keeps 4-character labels such as ISDB and BURN valid C strings, so later strcmp / "%s" in transcript output cannot read past the array.

No changelog update: this is a bug fix only. No new feature code.

NaitikVerma6776 and others added 2 commits September 1, 2026 18:58
strncpy of length 4 left 4-character strings such as ISDB and BURN without a terminator.

Co-authored-by: Cursor <cursoragent@cursor.com>
The format_rust CI job treats clippy warnings as errors. Initialize c_len in one expression so the check passes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@NaitikVerma6776

Copy link
Copy Markdown
Contributor Author

Greetings maintainers
The 70 failing tests are pre-existing and fail identically on master (see #2305) — this PR doesn't introduce any new test failures.

@ccextractor-bot

Copy link
Copy Markdown
Collaborator
CCExtractor CI platform finished running the test files on windows. 167/237 tests matched the approved output:
Report Name Tests Passed
Broken 9/13
CEA-708 2/14
DVB 0/7
DVD 3/3
DVR-MS 2/2
General 22/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 69/86
Teletext 0/21
WTV 12/13
XDS 31/34

70 tests do not match the approved output. That is the pass/fail verdict. Whether this branch caused it is a separate question, answered below.


Compared with the tip of mastertest 9495, commit 3af3fc2:

  • 1 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 69 fail on both, byte for byte the same

Pass there, fail here:


Compared with the commit this branch was cut from: the same run as the tip of master (test 9495), so the comparison above already covers it.


This branch changes the behaviour of 1 test(s) relative to the tip of master. Those are the ones worth looking at; anything else in the list fails the same way on both sides.

@cfsmp3
cfsmp3 self-requested a review September 5, 2026 19:16

@cfsmp3 cfsmp3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@NaitikVerma6776 The C bit looks good, but the Rust part is unrelated. Can just remove it and leave the C issue fix only?

@NaitikVerma6776

NaitikVerma6776 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

hey @cfsmp3 .... removed the Rust/clippy change. The PR is only the C fix in add_cc_sub_text now.

@cfsmp3
cfsmp3 merged commit 982586e into CCExtractor:master Sep 5, 2026
23 of 27 checks passed
@ccextractor-bot

Copy link
Copy Markdown
Collaborator
CCExtractor CI platform finished running the test files on linux. 167/237 tests matched the approved output:
Report Name Tests Passed
Broken 9/13
CEA-708 2/14
DVB 0/7
DVD 3/3
DVR-MS 2/2
General 22/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 69/86
Teletext 0/21
WTV 12/13
XDS 31/34

70 tests do not match the approved output. That is the pass/fail verdict. Whether this branch caused it is a separate question, answered below.


Compared with the tip of mastertest 9499, commit 3af3fc2:

  • 0 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 70 fail on both, byte for byte the same

Compared with the commit this branch was cut from: the same run as the tip of master (test 9499), so the comparison above already covers it.


No test changes behaviour relative to the tip of master: every failure above fails there too, byte for byte. The approved output for those tests is out of date, which is a baseline to review rather than a regression in this branch.

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.

[BUG] add_cc_sub_text does not NUL-terminate 4-character mode strings (ISDB/BURN)

3 participants