Commit Graph

3388 Commits

Author SHA1 Message Date
Carlos Fernandez Sanz
6f5d0b5259 Drop the previous file's bytes when opening a file (#2394)
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.
2026-10-17 21:50:29 -07:00
Carlos Fernandez Sanz
0bf2a94fe4 Reject malformed --buffersize, --sendto, --service (#2393)
--buffersize went through a lenient atol(): "abc", "12x" or an empty
value silently became 0, which is then clamped to an 8-byte file
buffer, and "3G" overflowed i32. It is now validated by clap: a byte
count with an optional K, M or G suffix, as documented, that fits in
an int.

--sendto parsed the port with unwrap(), so "host:abc", "host:" or an
out-of-range port aborted the process (SIGABRT). It is now validated
by clap through the same split used to assign the address and port.

--service parsed each service number with unwrap(), so a number too
large for usize aborted. It now reports the existing "Invalid service
number" error instead.

Valid values parse exactly as before; --help is unchanged.
2026-10-17 21:49:58 -07:00
Carlos Fernandez Sanz
89806871ea Document why store_hdcc overwrites the slot (#2392)
The comments around the reset in store_hdcc() say it was "changed to
concat" with a TODO, next to a commented-out stream_mode guard, which
reads as if the unconditional reset were a bug (issue #2350, PR #2351).

It is load-bearing. On a real ATSC MPEG-2 stream each picture carries
its 608 pairs twice, as SCTE-20 user data followed by GA94: every
same-slot store_hdcc() call in that file overwrites a block whose 608
pairs are identical to the GA94 block's. Appending instead duplicates
every character ("♪ S Standtandining g" for "♪ Standing"). None of the
other 40 local 608/708 samples ever stores twice into one slot.

Replace the stale comments with the reason and drop the dead
stream_mode lines. No code change.
2026-10-17 21:02:18 -07:00
Carlos Fernandez Sanz
4c03e90b39 Treat NULL as empty in the Levenshtein FFI exports (#2391)
C represents an empty compare buffer as (NULL, 0): telxcc resets
ucs2_buffer_cur to NULL after each buffer switch, and fuzzy_memcmp()
passes it on to levenshtein_dist() when a page carried no text.
slice::from_raw_parts requires a non-null pointer even for a zero
length, so ccxr_levenshtein_dist() was undefined behaviour there.
Debug builds abort on the precondition check (e.g. --tpages-all on
a teletext sample); release builds don't check it.

Build the slices through a helper that maps NULL to an empty slice,
and use it in ccxr_levenshtein_dist_char() too, which has the same
hazard.
2026-10-17 21:01:35 -07:00
Carlos Fernandez Sanz
83801f5af9 Fix zero timestamps for GXF/MXF ancillary captions (#2390)
GXF and MXF hand caption data to process_data() as CCX_RAW_TYPE
buffers with no video frames to anchor the timing. The caller has
already run set_current_pts() for each packet, which sets pts_set to
1, and set_fts() only reaches MinPtsSet after seeing a video frame
type, so the CCX_RAW_TYPE branch's "pts_set == 0" check never fired
and min_pts was never established. fts stayed at 0, every GXF
ancillary cue had zero length and SRT output was empty; MXF's first
cues were stamped 0 until timing was set some seconds in.

Establish min_pts in that branch whenever MinPtsSet hasn't been
reached, and take it from timing->current_pts, which the caller has
already rescaled to 90 kHz (data_node->pts is in GXF frame units).
2026-10-17 21:01:06 -07:00
Carlos Fernandez Sanz
d0410a6376 Fix EPG crash on empty extended event text (#2389)
EPG_decode_extended_event_descriptor() strips a leading character-table
byte from a continuation descriptor (descriptor_number > 0) when the
first text byte is below 0x20. When text_length is 0 that byte is not
text but whatever follows the descriptor, and the decrement wraps the
uint32_t length to 0xFFFFFFFF, so the following memcpy reads 4 GB and
--xmltv segfaults. An empty text field is legal: some broadcasters put
all extended event content in the item fields.

Only strip the byte when there is text to strip.
2026-10-17 21:00:40 -07:00
Arman Thakur
bee7481461 Report malformed time options instead of aborting (#2386)
--startat, --endat and the start/end credits timing options called
stringztoms(...).unwrap(), so a value such as "abc" panicked inside
ccxr_parse_parameters. A panic cannot unwind through the extern "C"
boundary, so the process aborted with SIGABRT (exit 134) and no
explanation. Report the value with ExitCause::MalformedParameter like
the other malformed parameters do.
2026-10-17 20:22:42 -07:00
Arman Thakur
b21a4c3c07 Print ccextractor.cnf warnings after the command line is parsed (#2385)
Warnings about bad lines in ccextractor.cnf were logged before the
command line was parsed, while the logger still targeted stdout. With
--stdout they ended up in front of the captions, and --quiet did not
silence them. Hold the messages back, point the logger at the parsed
messages target, then print them.

Also fix the FIX_PADDING and INVESTIGATE_PACKET tag typos in
docs/ccextractor.cnf.sample, add the missing '=' to tags that take a
value, and list the tags that are actually read.
2026-10-17 19:26:17 -07:00
Carlos Fernandez Sanz
22cb7e6a7d Document the build paths that enable FFmpeg/HARDSUBX (#2388)
#2354 pointed the Linux FFmpeg build at ./configure --enable-ffmpeg,
but linux/Makefile.am never uses the FFMPEG_IS_ENABLED conditional, so
that build has no FFmpeg support. On Linux only CMake enables it
(-DWITH_FFMPEG=ON, which links since #2357). Also drop the
ENABLE_HARDSUBX=yes make variable from HARDSUBX.txt: nothing reads it,
and ./configure --enable-hardsubx already enables the feature.
2026-10-17 19:15:47 -07:00
Chandragupt Singh
a5ffd09305 Stop FFmpeg libs preceding ccx_rust on the link line (#2357)
libccx.a propagated its FFmpeg libraries through INTERFACE_LINK_LIBRARIES, so on a plain -DWITH_FFMPEG=ON build they landed on the link line before rust/libccx_rust.a and GNU ld dropped them, leaving undefined avfilter/swscale symbols. Clear that propagation and drop the duplicate EXTRA_FFMPEG_LIBS append in the WITH_HARDSUBX block (WITH_HARDSUBX already forces WITH_FFMPEG). Plain, OCR and hardsubx builds link the same libraries as before; -DWITH_FFMPEG=ON now links.
2026-10-17 19:08:02 -07:00
NAMAN SHARMA S
fe00722960 Fix outdated make ENABLE_* build commands in docs (#2354)
docs/FFMPEG.md and docs/raspberrypi.md instructed `make ENABLE_FFMPEG=yes`
and `make ENABLE_OCR=yes`, but the Linux build is autoconf-based:
--enable-ffmpeg and --enable-ocr are ./configure flags (linux/configure.ac),
not make variables, so these commands did nothing. raspberrypi.md also
skipped the ./autogen.sh/./configure steps entirely.


Claude-Session: https://claude.ai/code/session_014qdK9kxULTrqFjbYUzdwfP

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-17 19:05:34 -07:00
Carlos Fernandez Sanz
fb5c160483 Compute FFmpeg tx3g end time in one step (#2387)
#2378 derives the end of a tx3g cue as start_ms + duration * 1000 /
timescale. Both terms are truncated separately, so the end can land
1 ms before the GPAC path's, which converts pts + duration at once.
On a real m4v with 797 cues, 99 ended 1 ms early (e.g. timescale
600, pts 135725, duration 2725: 230749 instead of 230750).
2026-10-17 18:57:36 -07:00
dependabot[bot]
f93f9f5185 chore(deps): bump rust-toolchain from 1.99.0 to 1.99.1 (#2381)
Bumps [rust-toolchain](https://github.com/rust-lang/rust) from 1.99.0 to 1.99.1.
- [Release notes](https://github.com/rust-lang/rust/releases)
- [Changelog](https://github.com/rust-lang/rust/blob/main/RELEASES.md)
- [Commits](https://github.com/rust-lang/rust/compare/1.99.0...1.99.1)

---
updated-dependencies:
- dependency-name: rust-toolchain
  dependency-version: 1.99.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-10-17 17:33:47 -07:00
Pratham Jaiswal
a6922e180f [FIX] Use packet timestamps for tx3g subtitle times on the FFmpeg MP4 path (#2378)
The tx3g start/end times came from the global timing pointer, which every
track shares: it can already be past the subtitle being processed, and on
the very first subtitle it is still at zero. Result on a tx3g MP4
with subtitles at 1s-3s and 4s-6s:

  1: 00:00:00,000 --> 00:00:03,999
  2: 00:00:04,000 --> 00:00:09,959

Take the times from the packet timestamps directly instead: the start is
the packet PTS in milliseconds and the end is the sample duration when
present, with the previous behaviour as fallback (next subtitle's start,
or the usual 5 second default for the last sample). The timing pointer is
still set from the explicit start, it is just no longer used to derive
the output times.

Output now matches the GPAC path exactly:

  1: 00:00:01,000 --> 00:00:02,999
  2: 00:00:04,000 --> 00:00:05,999
2026-10-17 17:31:41 -07:00
harshal
aed3c8ae14 [FIX] Matroska: free BlockAddition data when tearing down WebVTT tracks (#2375)
free_sub_track() never released sentence->blockaddition, nor the message
buffer that parse_segment_cluster_block_group_block_additions() allocated
for it, so every WebVTT sentence with BlockAdditions leaked.

Store the base allocation in the struct and free it in free_sub_track().

Co-authored-by: Harshal <harshal@iitbhilai.ac.in>
2026-10-17 17:29:39 -07:00
pranayr710
14de6693cd Add .gitattributes so POSIX scripts stay LF on Windows clones (#2346)
Git for Windows defaults to core.autocrlf=true, which rewrites LF to CRLF
on checkout. The tree has no .gitattributes, so nothing stops that from
reaching the shebang of every POSIX script, and a clone made on Windows
cannot run the build documented in docs/COMPILATION.MD or the
local-source Docker build in docker/README.md:

    $ ./pre-build.sh
    /usr/bin/env: 'bash\r': No such file or directory
    exit=127

Pin the shell scripts to LF, and the Windows batch/PowerShell scripts to
CRLF, on every platform.

Deliberately narrow: no "* text=auto". 978 tracked files are committed
with CRLF and normalising them would be a repo-wide rewrite unrelated to
this fix. Verified that adding this file changes no tracked content.
2026-10-17 17:14:23 -07:00
K Soveet Kumar Prusty
1ed98195d0 [FIX] Reject malformed extraction times before they abort the parser (#2374)
* fix(parser): validate extraction times before the C ABI call

Generated-by: OpenAI Codex

* docs(parser): clarify extraction time limit and correct parse error
2026-10-17 17:13:28 -07:00
Deepak
af4b28d8cc [FEATURE] Port ccextractor.cnf config file support to Rust (#2369) 2026-10-17 16:59:05 -07:00
Carlos Fernandez Sanz
8ed92317e4 Accept the remaining v0.94 option spellings (#2383)
The C parser in v0.94 accepted short and underscore spellings such as
-nofc, -bi, -gt, -haup, -ocr_mode and --gui_mode_reports. The Rust
parser rejects 46 of them with "Unknown Argument", so old scripts and
frontends stop working. #2368 covered nine; this covers the rest that
still have an equivalent option.

Each spelling becomes a hidden clap alias on the option with the same
behaviour, so --help is unchanged and option values are still skipped
by normalize_legacy_args. -ntm/--no-timestamp-map get a hidden no-op
flag: v0.94 wrote the X-TIMESTAMP-MAP header by default and this
turned it off, but the header is now off unless --timestamp-map is
given.

The sharing and translation options (-enable-sharing, -sharing-url,
-sharing-debug, -translate, -translate-auth) stay rejected because
that feature no longer exists. -curlposturl already works in builds
with libcurl, as in v0.94.
2026-10-17 16:57:08 -07:00
Carlos Fernandez Sanz
6370ecf27a Drop Corrosion's hard-coded CLT SDK link dir on macOS (#2384)
Corrosion adds /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
as an interface link directory of the Rust static library on macOS
(still the case in Corrosion 0.6.1). Since the macos-26-arm64 runner
image of 2026-10-13, that symlink points to a macOS 27 SDK while the
selected toolchain is Xcode 26.6, and its ld rejects the 27 SDK's .tbd
stubs ("unknown architecture"). Every macOS CMake build has failed to
link since.

The libraries rustc asks for (-lSystem -lc -lm) resolve through the
compiler's own SDK without the extra -L, as the shell and autoconf
builds on the same runner show, so clear the property.
2026-10-17 16:38:27 -07:00
Deepak
353c41e268 [FIX] Accept remaining legacy single-dash option spellings (#2368)
Follow-up to #1856. Add hidden clap aliases for case variants the C parser accepted (UCLA, CC2, LF, DF, parsepat, parsepmt) and map -608, -708, -90090 in normalize_legacy_option. Fix --gui-mode-reports spelling in FRONTEND_COMMUNICATIONS.TXT.
2026-10-17 15:42:51 -07:00
Deepak
13d33722fa [FIX] Accept negative --delay values as a separate argument (#2370) 2026-10-17 15:37:23 -07:00
Carlos Fernandez Sanz
a168c7130a Add missing braces in MCC CDP split loop (#2382)
The chunk-size clamp added in #2366 has a braceless if body, which
the project style forbids on every if/else/for/while. No behaviour
change.
2026-10-17 15:36:02 -07:00
Arman Thakur
429de8bc43 Split MCC output into CDPs of at most 31 triplets (#2366)
The cc_count field of a CDP's ccdata_section is 5 bits wide, but
mcc_encode_cc_data() wrapped a whole frame's cc_data into a single CDP.
Above 31 triplets the stored count kept only its low 5 bits (32 was
written as 0). From 82 triplets the uint8 length bytes overflowed, and
from 86 the uint8 data_size wrapped, so add_boilerplate() allocated a
short buffer that count_compressed_chars() and compress_data() then read
past (heap-buffer-overflow under ASan).

Write one CDP per chunk of up to 31 triplets instead, each on its own
line with the same time code, which the MCC format allows.

Fixes #2365
2026-10-17 15:33:36 -07:00
Carlos Fernandez Sanz
97a0d24832 Read GXF TRACK_AUX sizes as little-endian (#2373)
#2364 replaced the native int16_t reads of field_size and packet_size
in parse_ad_track_desc() with RB16, following a stale "RB16" comment.
The ancillary-data TRACK_AUX block is little-endian: FFmpeg reads and
writes it with avio_rl64/avio_wl64, and parse_ad_packet() checks
field_size against a little-endian value in the media packet (4676
SD, 6340 HD). The old native read was correct on little-endian hosts.

With RB16, a field_size of 4676 becomes 17426 and a packet_size of
256 units becomes 1, so every ancillary media packet is parsed with
the wrong field boundaries and its captions are lost. RL16 restores
the previous values without the unaligned, type-punned read.
2026-10-11 12:34:45 -04:00
pranayr710
0ee3b7a6b7 Use RB16/RB32 for the remaining direct multi-byte casts (#2364)
Follow-up to #2353, which fixed the utility.h macros themselves. The same
pattern survives as hand-written casts at the sites noted in that review,
plus two more in mp4.c's HEVC path.

Each one casts an arbitrary byte pointer to a wider type and dereferences
it, which is undefined behaviour twice over: the offset has no alignment
guarantee (C11 6.3.2.3p7) and it reads a byte array through an
incompatible lvalue type.

mp4.c (4 sites: AVC and HEVC, 2-byte and 4-byte NAL length prefixes).
This one is not just UB. nal_length is u32 but bswap16() returns a signed
int16_t, so a NAL unit of 32768..65535 bytes comes back negative, sign
extends to roughly 4e9, fails the "i + nal_length > s->dataLength" bounds
test and is silently skipped along with any captions it carries. RB16
returns uint16_t and the length survives. bswap16/bswap32 have no callers
left and are removed.

ts_tables.c (2 sites). The PMT CRC fingerprint. Value changes from a
native-endian read to big-endian, but it is only ever compared against
itself to detect an unchanged PMT, so nothing downstream can observe it.

ccx_gxf.c (2 sites). field_size and packet_size. The surrounding comments
already read "// RB16(auxi_info + 4);" so the intent was there. GXF is
big-endian, so this corrects the values as well as removing the UB -- see
the PR description, this is the one hunk I could not verify locally.

Regression: 7 TS inputs x 13 output formats = 91/91 identical exit codes,
output hashes and stdout hashes against master built from the same source
in the same image. No new compiler warnings.
2026-10-11 12:14:35 -04:00
Carlos Fernandez Sanz
934f63be1e Guard two more short-payload reads in TS parsing (#2372)
Both were found while verifying #2349 and are reachable from stream
data:

- parse_SDT passes section_length - 4 - 8 to the services loop, and
  section_length comes from the stream. Below 12 (the smallest legal
  section: 8 bytes of fields plus the CRC) the unsigned subtraction
  wraps and the loop reads past the buffer. It got past both existing
  length checks.

- read_video_pes_header reads the PES length and nextheader[6] before
  its own sbuflen < 9 check. With #2349 stopping the earlier crash in
  ts_readstream, a capbuf holding only a 3-byte start code now reaches
  it when flushed at EOF and is read past its end. Return -1 for a
  caller buffer shorter than 7 bytes, as the < 9 path already does.
2026-10-11 11:40:23 -04:00
Arman Thakur
c1043ca7d4 [FIX] Raise ccxr_process_cc_data cap from 31 to the real hdcc slot capacity (310) (#2359)
* [FIX] Raise ccxr_process_cc_data cap to the real hdcc slot capacity (310)

Addresses item 1 of #2358.

ccxr_process_cc_data() rejected any call with more than 31 caption
triplets (MAX_CC_COUNT, added in #2241 as an overflow guard). 31 is the
limit of the 5-bit cc_count field in a single cc_data() header, but this
function receives a whole buffered frame from process_hdcc(). An H.264
access unit carrying several GA94 SEI messages adds them together in
avc_ctx->cc_count, so it can pass 31 even though every SEI in it is
valid. When it did, the frame's entire CEA-708 payload was discarded.
The warn!() is not shown at the default log level, so users saw no sign
of the loss. CEA-608 was not affected, because the C do_cb() loop
doesn't check the cap.

Changes:

- ccx_decoders_structs.h: add HDCC_MAX_TRIPLETS_PER_SLOT (10 * 31) and
  use it to size cc_data_pkts instead of an inline literal.
- lib.rs: move MAX_CC_COUNT to module level and set it to 310, the
  capacity of one cc_data_pkts slot, and cross-reference the C
  constant. The new test max_cc_count_matches_hdcc_slot compares it with
  the slot size in the bindgen-generated lib_cc_decode, so CI fails if
  the C and Rust values drift apart.
- sequencing.c, init_hdcc(): the memset cleared SORTBUF * (31 * 3 + 1)
  bytes, about 10% of cc_data_pkts. It now uses the real size.
- sequencing.c, store_hdcc(): bounds-check both write paths against
  cc_data_count[seq_index] + cc_count. On overflow, clamp to the slot
  capacity, always keep the 0xFF end marker process_hdcc() expects, and
  warn once per run. No current caller can reach this (the largest is
  H.264's u8 cc_count, at most 255), but it closes the slot overflow
  that opens once #2350 makes writes append to the slot.

Tested on a synthetic H.264 TS (libx264, B-frames) with 16 + 16 = 32
triplets per access unit: master writes no CEA-708 output, while this
change decodes both CEA-708 captions. A 15 + 15 = 30 control decodes
identically on both, which confirms the cap is the cause. CEA-608
output, and the MPEG-2 regression samples, are byte-identical to
master. cargo test passes (403).

MCC chunking (#2358 items 2-3) is left for a separate change.

* fix(doc): clarify HDCC triplet capacity comment

* fix: drop store_hdcc truncate/clamp blocks

Per review: these checks are unreachable today, since every data write
resets cc_data_count[seq_index] to 0 right before the check and no
caller
passes cc_count > 255. They belong with the fix for #2350, where
appending writes make them reachable. HDCC_MAX_TRIPLETS_PER_SLOT and the
init_hdcc memset fix stay.
2026-10-11 11:28:31 -04:00
pranayr710
cde38d1070 [FIX] TS: guard three out-of-bounds reads on short packet payloads (#2349)
* [FIX] TS: guard three out-of-bounds reads on short packet payloads

A transport stream packet whose adaptation field leaves a very short
payload drives three out-of-bounds reads. All are reachable from stream
data and all are caught by AddressSanitizer.

1. parse_PAT() (ts_tables.c) - heap-buffer-overflow.
   pointer_field is a raw byte from the stream and buffer_length is
   uint32_t, so buffer_length - (pointer_field + 1) underflows to ~4e9
   and slips past the "payload_length < 8" guard. With
   adaptation_field_length 182 the PSI buffer holds exactly one byte, and
   ASan records a read 184 bytes past that 1-byte allocation.

2. parse_SDT() (ts_tables.c) - same underflow, and no length check at all
   before reading payload_start[0..2].

3. ts_readstream() (ts_functions.c) - global-buffer-overflow.
   The PES/PTS block dereferences payload.start[0..3] without checking
   payload.length. adaptation_field_length 183 leaves zero payload bytes
   and payload.start pointing one past the end of the 188-byte tspacket
   global. get_pts() reads through buffer[13], hence the >= 14 guard.

All three now match the bounds check already used at
ts_tables_epg.c:1642.

Verified against master built from identical source in the same image:

  ASan, --out=srt          master -> fixed
    af_182.ts                  1 -> 0
    af_181.ts                  1 -> 0
    af_180.ts                  1 -> 0
    pusi_af183.ts              1 -> 0
    valid.ts                   0 -> 0

  Output regression: 12 TS inputs x 13 formats = 156/156 identical
  (exit code, output hash and stdout hash; the MCC "Creation Time"
  header is wall-clock and is excluded).

* Address review: guard parse_SDT section length and the capbuf PES check

Follow-up to the review on #2349. Two more sites of the same class, plus
the brace style.

parse_SDT: the pointer_field guard only stopped the underflow. With
pointer_field = 0 and a two-byte section, payload_length is 1 and
payload_start[1..2], [5] and the services loop based at [11] still read
past the buffer; "section_length > payload_length - 4" underflows too.
Require payload_length >= 12, which covers every field read up to the
services loop, mirroring parse_PAT's "payload_length < 8".

copy_payload_to_capbuf: with capbuflen == 0 the PES start code is read
from payload->start[0..2] without checking payload->length. A PUSI packet
whose adaptation field leaves one byte is a global-buffer-overflow there.
Fold "payload->length < 3" into the existing condition so a payload too
short to hold a start code takes the same "Missing PES header" path
rather than being inspected -- skipping the check instead would let an
unverified short payload into capbuf.

Braces added to the two single-statement if bodies from the first commit.

Both reproduce on the previous revision of this branch, from the recipes
in the review (PID 0x11 PUSI AF 181 payload "00 42" with --xmltv 1, and
PID 0x101 PUSI AF 182 payload "00"):

  rev_sdt.ts     heap-buffer-overflow   ts_tables.c:971
  rev_capbuf.ts  global-buffer-overflow ts_functions.c:686
2026-10-11 11:24:10 -04:00
Carlos Fernandez Sanz
cad10b6c6e [IMPROVEMENT] Bump Rust toolchain to 1.99.0 and fix its new lint (#2363)
* chore(deps): bump rust-toolchain from 1.98.1 to 1.99.0

Bumps [rust-toolchain](https://github.com/rust-lang/rust) from 1.98.1 to 1.99.0.
- [Release notes](https://github.com/rust-lang/rust/releases)
- [Changelog](https://github.com/rust-lang/rust/blob/main/RELEASES.md)
- [Commits](https://github.com/rust-lang/rust/compare/1.98.1...1.99.0)

---
updated-dependencies:
- dependency-name: rust-toolchain
  dependency-version: 1.99.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Declare realloc by hand for Rust 1.99

rustc 1.99 adds the suspicious_runtime_symbol_definitions lint, which
fires on the bindgen-generated realloc binding because bindgen types
its size argument as c_ulong rather than usize. With -D warnings this
fails the format_rust check on the toolchain bump.

Declare realloc next to free in ffi_alloc.rs with the size_t-correct
signature and drop it from the bindgen allowlist. The only caller,
avc/core.rs, now imports it from there. No behaviour change.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-10-11 10:36:50 -04:00
Carlos Fernandez Sanz
6e9c8cba1d Add missing braces in processmp4 frame-type check (#2362)
The if body extended in #2321 still has no braces, which the project
style requires on every if/else/for/while body. No behaviour change.
2026-10-01 20:33:12 -07:00
Shubh Rai
e313f709a0 fix: correctly initialize frame type for tx3g and mov_text subtitles (#2321)
* fix: correctly initialize frame type for tx3g and mov_text subtitles

* fix: update comment and condition order for subtitle tracks
2026-10-01 17:07:57 -07:00
pranayr710
ad4f139d07 Read multi-byte values byte-wise in utility.h instead of casting the pointer (#2353)
RL32/RB32/RL16/RB16 cast an arbitrary byte pointer to a wider type and
dereference it:

    #define RB32(x) (ntohl(*(unsigned int *)(x)))
    #define RB16(x) (ntohs(*(unsigned short int *)(x)))

That is undefined behaviour twice over. The offset carries no alignment
guarantee (C11 6.3.2.3p7), and it reads a byte array through an
incompatible lvalue type. Both are reachable at every call site, because
all 28 of them index into a demuxed packet at an offset the stream
chooses:

    RB32  5 sites   ccx_gxf 2, dvb_subtitle_decoder 1, mp4 1, mp4_rust_bridge 1
    RB16 23 sites   dvb_subtitle_decoder 15, ccx_gxf 4, ccx_decoders_isdb 1,
                    mp4 1, mp4_rust_bridge 1, ts_tables 1

UBSan already reports the same pattern elsewhere in the tree, e.g.

    ts_tables.c:128: runtime error: load of misaligned address for type
    'int32_t', which requires 4 byte alignment

RB24, three lines below in the same block, was already written byte-wise.
The other four now match it, which also drops the ntohl/ntohs dependency.

No value change: old and new definitions were compiled side by side and
compared over 16,777,216 byte patterns x 4 macros -- 0 mismatches.

Output regression: 7 inputs (TS, RCWT, SCC, raw) x 13 formats = 91/91
identical exit codes, output hashes and stdout hashes.

RL32 and RL16 have no call sites today; they are fixed rather than removed
so the block stays consistent.
2026-10-01 09:18:23 -07:00
Naitik Verma
aa1b739179 [FIX] Do not switch input files while detecting stream type (#2347)
The default Rust open() path probed 1MB with binary_concat still on, so a short file's EOF re-entered switch_to_next_file and advanced current_file twice. Disable concat around detect, matching the existing C guard.
2026-10-01 09:00:42 -07:00
Carlos Fernandez Sanz
670a5ab50d Add missing braces in dtvcc_process_cr (#2360)
The no-rollup block added in #2318 left the for loop and the else
branch without braces, which the project style requires on every
if/else/for/while body. No behaviour change.
2026-10-01 08:49:12 -07:00
nlp201
36d28ad5a6 [FIX] Clear stale CEA-708 window rows in no-rollup mode (#2318)
* [FIX] Clear stale CEA-708 window rows in no-rollup mode

* test: fix CEA-708 no-rollup fixture stack usage

---------

Co-authored-by: nlp201 <13403166+nlp201@users.noreply.github.com>
2026-10-01 08:46:52 -07:00
Arman Thakur
b113f8618f [FIX] Warn when non-DVB caption PIDs are silently ignored (#2334)
* [FIX] Warn when non-DVB caption PIDs are silently ignored

Closes #2333

When a program contains multiple caption-carrying PIDs of the same
non-DVB codec (Teletext, ISDB, or ATSC), only one is ever decoded —
every other same-type PID is silently discarded with no warning, no
log line, and no indication to the user that a second language track
existed.

This adds a warning at the actual root cause: the DVB-only exemption
in `ignore_other_stream()` and `ignore_other_sib_stream()`
(`src/lib_ccx/ts_info.c`). A new static helper,
`warn_ignored_caption_stream()`, prints the ignored PID and points the
user to `--datapid` to recover it manually. DVB is explicitly excluded
since it already has its own extra-PID handling and doesn't need this.

**Scope**: this is a warning only. It does NOT add multi-PID decoding
support for Teletext/ISDB/ATSC — see #2333 for why that's a separate,
larger effort (per-PID decoder allocation, per-language encoder
routing, and ISO-639 storage for Teletext don't exist today for
non-DVB codecs).

**Real broadcast sample** (two Teletext PIDs, one program — from
samples.ffmpeg.org/ffmpeg-bugs/trac/ticket3514):

$ ccextractor --tpages-all t3514.ts
VBI/teletext stream ID 3401 (0xd49) for SID 1002 (0x3ea)
VBI/teletext stream ID 3402 (0xd4a) for SID 1002 (0x3ea)
Warning: Teletext caption stream ID 3402 (0xd4a) for SID 1002 (0x3ea)
will be ignored - only one caption stream per program is extracted.
Use --datapid 3402 to extract it in a separate run.

Correct PID, correct SID. The 8 DVB subtitle PIDs in the same file stay
silent, as expected.

**Synthetic two-PID split** (dvbteletext.ts split across two PIDs):
same correct behavior, warns on the dropped PID (202/0xca).

**ISDB and ATSC branches** — verified against a constructed sample
(`mixed_codecs.ts`, built from `dvbteletext.ts` by injecting two ES
entries into its PMT: PID 0xca as ISDB via a data_component descriptor,
PID 0xcb as ATSC via a caption_service descriptor):

$ ccextractor --tpages-all mixed_codecs.ts
VBI/teletext stream ID 201 (0xc9) for SID 201 (0xc9)
*****ISDB subtitles detected
Warning: ISDB caption stream ID 202 (0xca) for SID 201 (0xc9) will be
ignored - only one caption stream per program is extracted.
Use --datapid 202 to extract it in a separate run.
Warning: ATSC caption stream ID 203 (0xcb) for SID 201 (0xc9) will be
ignored - only one caption stream per program is extracted.
Use --datapid 203 to extract it in a separate run.

Teletext output (`mixed_codecs_p694.srt`, `_p765.srt`) is byte-identical
to the unmodified `dvbteletext.ts` baseline — the injected PIDs change
nothing except triggering the new warnings.

Note: I could not source a real multi-PID ISDB recording — the one
public ARIB sample I found (samples.ffmpeg.org/MPEG2/subcc, single PID)
has a multi-TS-packet PMT my synthetic splitter doesn't handle, so the
ISDB/ATSC branches above are exercised by a constructed sample rather
than a genuine broadcast recording. Flagging this rather than implying
otherwise — the Teletext path is verified on real broadcast data (see
above), ISDB/ATSC are verified by construction.

**DVB control** — confirms no regression: ran both a single-PID and a
split two-PID DVB sample before and after the patch. No new warnings
on either, and output is byte-identical (PNG counts and `diff -rq`
match exactly pre- and post-patch). All decoded `.srt` files from the
Teletext samples are also byte-identical to their pre-patch versions —
this change only adds a print statement, no decoding logic is touched.

**Caught during testing, fixed before this PR**: the first version of
this warned on every video PID in every file, because 608/708 captions
are internally tagged `CCX_CODEC_ATSC_CC` even though they live inside
the video stream, not a separate PID (`ts_tables.c:492-498`). Fixed by
excluding `CCX_STREAM_TYPE_VIDEO_MPEG2/_H264/_HEVC` from the warning.
Re-verified against a European DVB file (now silent, as it should be)
and a US ATSC file with real 608/708 captions in video (still silent,
correct — genuine caption-only ATSC PIDs still warn correctly).

**Known cosmetic issue, pre-existing, not introduced by this patch**:
under `--pmt`, the ATSC warning can visually run together with a
preceding debug line (`ts_tables.c:445-449` emits its `dbg_print`
without a trailing newline, so whatever prints next collides with it
on the same line). This only occurs with `--pmt` and would happen with
any output following that debug line, not just this warning. Out of
scope for this PR per its stated scope, noting it here so it isn't
mistaken for something this patch caused.

**Reason for this PR:**
- [ ] This PR adds new functionality.
- [x] 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:**
- [x] I have read and understood the contributors guide.
- [x] I have checked that another pull request for this purpose does not
  exist.
- [x] 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.
- [x] I am NOT adding new C code unless it's to fix an existing,
  reproducible bug.

* fix: caption stream warning format specifiers
2026-09-22 19:44:24 -07:00
Carlos Fernandez Sanz
2364994a91 Fix stale input-file index after open in switch_to_next_file (#2343)
switch_to_next_file() validates current_file, then calls open() and
re-reads inputfile[current_file] afterwards. open() reaches
buffered_read_opt(), which calls switch_to_next_file() again when
binary_concat is set, and that advances current_file. The index the
caller validated no longer points at the file it opened, and with the
last file it points one past the end of the array.

Passing two input files therefore segfaults: the Rust copy dereferences
inputfile[2] of a two-element array and hands the garbage pointer to
CStr::from_ptr. With one file it is an 8-byte read past the allocation,
which valgrind reports on any run.

Hold the name before calling open() and use it afterwards, in both the C
function and its Rust port. Neither re-reads the index it no longer owns.
2026-09-12 16:36:40 -07:00
pranayr710
cb421dbec6 [FIX] Use fixed-width format specifiers for 64-bit values (#2337)
X-TIMESTAMP-MAP emitted a truncated MPEGTS value on every Windows build.
sync_pts2fts_pts is LLONG (int64_t) but was printed with %ld, and long is
32 bits on Windows (LLP64 on x64, ILP32 on Win32). A 90kHz PTS of 2^33
printed as "MPEGTS:0"; 2^31 printed as "MPEGTS:-2147483648". On Win32 the
argument slots also desynchronise, so the trailing %s reads the PTS high
dword as a char *. HLS players use this field to anchor a WebVTT segment
to the transport clock, so the result is caption desync.

Linux and macOS are LP64, where long is 64 bits and %ld happens to be
correct, which is why this went unnoticed. For the same reason %lld would
be wrong there, since int64_t is long on LP64. Use the <inttypes.h> macros
instead, which are correct on every target and already used elsewhere in
the tree; ccx_common_platform.h already includes <inttypes.h>.

The same defect class appears at 22 sites across 10 files. They are
invisible to the build because mprint() and dbg_print() carry no
format(printf) attribute, so the compiler never checks those call sites.
Adding the attributes locally surfaced all of them; this commit fixes them
with PRId64/PRIu64/PRIx64 for fixed-width types, %zu for size_t, and an
explicit (long long) cast for pointer differences.

Also fixes ts_readpacket() printing payload->start, an unsigned char *,
under the label "PES start". The intended field is payload->pesstart; the
pointer was truncated to int and shifted the three arguments after it, so
counter, payload length and adapt length were all wrong in the trace.

Output on Linux and macOS is byte-identical before and after. No
signature, struct, option or output-format change.

Refs #2336
2026-09-12 15:41:21 -07:00
pranayr710
683bb39d4b [FIX] webvtt: don't leak basefilename or skip the header flag on CSS failure (#2339)
write_webvtt_header() is called once per cue and guards re-entry with
context->wrote_webvtt_header, which it sets on its last line. The
--webvtt-create-css path returned early when the .css file could not be
created, bypassing that assignment, so the whole header block was written
again before every subsequent cue. The existing trailing comment ("Do it
even if couldn't write the header, because it won't be possible anyway")
already stated the intent.

Replace the early return with an else branch so the flag is always
reached, and move free(css_file_name) after it so both paths release it.

basefilename came from get_basename(), which allocates, but was never
freed on any path. Every other caller in the tree frees it. On its own
that is one small leak per output file; together with the early return it
became a leak per cue.

Refs #2338
2026-09-12 14:25:49 -07:00
pranayr710
4405f958fc [FIX] encoder_ctx: zero the struct so timing starts out NULL (#2342)
ccextractor sample.rcwt --out=webvtt --timestamp-map segfaults.

init_encoder() allocates encoder_ctx with malloc and assigns 60 of its 74
members. timing is one of the nine it does not touch, and it is only set
later in general_loop(), the DVB path, mp4.c, and raw_loop() -- the last
of these only when the output format is MCC. rcwt_loop(), process_hex()
and raw_loop() for every other format therefore leave it holding
indeterminate heap contents.

write_webvtt_header() guards the field with "context->timing != NULL"
before reading sync_pts2fts_set. The guard is correct, but an
indeterminate value is almost never NULL, so it passes and the read
dereferences a wild pointer. --timestamp-map is the only thing that makes
timing be read on this path, which is why the crash needs that flag.

Allocate with calloc so every member starts zeroed. The 60 assigned
members are unaffected; timing becomes NULL and the existing guard works
as written, so RCWT input skips X-TIMESTAMP-MAP instead of crashing --
which is the right result, since sync_pts2fts_set would be 0 there.

Verified by building master and this change from identical source in the
same image: exit 139 -> exit 0, and output across 13 formats (webvtt, srt,
sami, ttxt, txt, scc, ssa, smptett, g608, mcc, spupng, simple_xml, rcwt)
is byte-identical, same exit codes and same SHA-256 hashes.

Refs #2340
2026-09-12 11:30:42 -07:00
Guflly
907be052e9 fix: make FFmpeg MP4 diagnostics format-safe (#2314) 2026-09-06 07:50:46 -07:00
Chandragupt Singh
205cfb0989 ci: pin Rust toolchain to 1.98.1 via rust-toolchain.toml (#2335) 2026-09-06 07:41:39 -07:00
Chandragupt Singh
3875e84351 Remove unreachable post-return C bodies and their orphaned helpers in es_functions.c (#2327) 2026-09-05 18:09:44 -07:00
Arman Thakur
2ad84df33e [FIX] chore: remove two dead includes flagged by clangd (#2329)
ccx_common_char_encoding.h in ccx_decoders_common.c is unused —
the functions it declares moved to ccx_encoders_common.c after a
2014 refactor and the include was never cleaned up.

ccx_demuxer_mxf.h in general_loop.c is also unused — general_loop.c
handles MXF via ccx_mxf_getmoredata, which is already declared in
lib_ccx.h (included separately). This header appears to have been
added by reflex alongside MXF support in 2017 without ever being
needed.

A third flagged include, ffmpeg_intgr.h in general_loop.c, was
investigated and left untouched — it's a genuine dependency under

Closes #2328
2026-09-05 15:03:58 -07:00
Carlos Fernandez Sanz
cf42e6cb05 Fix clippy needless_late_init in txt_helpers (#2332)
Master fails `cargo clippy -- -D warnings` on lib_ccxr, so format_rust
is red on every open pull request regardless of what it changes. Authors
have been fixing it inside unrelated PRs to get their CI green, which
couples a one-line lint fix to whatever else they are working on.

Assign c_len from an if-expression instead of declaring it and filling
it in on each branch. Behaviour is identical.
2026-09-05 14:58:33 -07:00
Naitik Verma
982586e824 [FIX] NUL-terminate mode/info strings in add_cc_sub_text (#2331)
* fix: NUL-terminate mode and info in add_cc_sub_text

strncpy of length 4 left 4-character strings such as ISDB and BURN without a terminator.

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

* fix: satisfy clippy needless_late_init in txt_helpers

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>

* Revert "fix: satisfy clippy needless_late_init in txt_helpers"

This reverts commit fc7ab9781d.

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-05 13:11:27 -07:00
Chandragupt Singh
5dca95bec9 fix(transcript): wrote_something |= write_cc_line_as_transcript2() to suppress spurious blank lines (#2324) 2026-09-05 12:33:33 -07:00
Carlos Fernandez Sanz
3af3fc2244 fix(file_functions): correct three integer conversions in the read path (#2325)
get_file_size() stored an LSEEK result in an int. LSEEK returns a 64-bit
offset, so a successful seek back to a position at or beyond 2 GB truncated
to a negative int and the function reported failure for a seek that worked.
ccx_demuxer_get_file_size() is the same routine written correctly with an
LLONG; this copy had drifted. Latent today -- the only caller opens each file
fresh, so the position is always 0 -- but it is a trap for the next caller.

buffered_read_opt() computed the bytes left in the file buffer as
"bytesinbuffer - filebuffer_pos" on two unsigned ints. That is the underflow
that made the bounds checks in file_buffer.h pass when they should have
failed; the helper added to fix those, buffered_bytes_left(), belongs here too.

The end-of-input test compared inputsize, a signed 64-bit size, against
origin_buffer_size, a size_t. The usual arithmetic conversions turned a
negative inputsize -- what get_filesize() returns when the size cannot be
determined -- into a huge unsigned value, so the test silently read as "the
input is enormous". The comparison is now spelled out. An unknown size still
does not count as fitting in one read, and the short-circuit order is
unchanged, so switch_to_next_file() is called exactly when it was before.

Verified against the current master binary: byte-identical output on 99 files
from the sample library, and on the --bufferinput, multi-file concat and
stdin paths, with matching exit codes throughout.
2026-08-15 08:48:55 -07:00
Carlos Fernandez Sanz
128175ea7b fix(encoder): don't return the list iterator when no encoder matches (#2319)
update_encoder_list_cinfo() declares enc_ctx uninitialised and uses it as the
list_for_each_entry() iterator. For a DVB stream carrying a language, the search
loop continues past every encoder whose dvb_lang does not match, so it can finish
without returning. When the encoder list is non-empty none of the creation
branches below run either, and the function falls through to

    enc_ctx->prev = NULL;

with enc_ctx still holding the value the loop terminated on: the list head
reinterpreted as an encoder_ctx. That pointer is written to, and later
general_loop.c does dvb_enc->timing = dvb_dec->timing on it, which segfaults.

It reproduces on any recording that carries both a teletext stream and a DVB
subtitle stream, in every output format, with no extra flags:

    ccextractor --out=srt  sample.mpg   -> SIGSEGV
    ccextractor --out=webvtt sample.ts  -> SIGSEGV

Restricting to one PID (--datapid) avoids it, which is why the regression suite
never caught it: the only affected sample it runs passes --datapid.

Clear the iterator after the loop so "not found" is distinguishable, and give
such a stream its own per-language encoder, which is what the multi-DVB path
already does. The existing dvb_pid_count >= 2 test stays as an OR so a recording
whose only caption stream is a single DVB PID keeps its plain output filename --
that case reaches the standard path with an empty encoder list. A NULL guard
before the tail keeps the fall-through honest if some future path adds one.

Both streams are now extracted into separate, well-formed files (out.srt plus
out_eng.srt) rather than one file with two interleaved numberings.
2026-08-13 07:53:49 -07:00