Commit Graph

3402 Commits

Author SHA1 Message Date
Deepak
f4519fff91 [FIX] Sort capitalization and profanity word lists so bsearch finds the words (#2397) 2026-11-10 09:02:39 -08:00
Deepak
672f012805 [FIX] Use seconds for the --stream timeout in the Rust code (#2426) 2026-11-10 08:54:35 -08:00
Deepak
cccad8ff09 [FIX] Accept --stream with one input file and without a timeout value (#2415) 2026-11-10 08:51:13 -08:00
Chandragupt Singh
9feaa78186 ci(appimage): build hardsubx against a vendored FFmpeg 7 (#2423) 2026-11-10 08:31:49 -08:00
Vishnu Srivatsava
e93758b581 [FIX] rcwt_loop: decide teletext mode once from the file header (#2430)
The loop re-read parsebuf[6..7] every iteration to choose between the
teletext and CEA-608 paths, but in 608 mode parsebuf is reused for data
headers and caption blocks, so raw caption bytes 00 02 at offsets 6-7
routed the stream into tlt_read_rcwt() with a NULL teletext context
(SEGV in telxcc.c, memcpy to NULL->last_timestamp).

Capture the decision in a flag right after the 11-byte file header is
validated, and use it inside the loop.
2026-11-10 07:32:38 -08:00
pranayr710
8d835e6a44 [FIX] WTV: bound the metadata lengths read_header() takes from the file (#2435)
read_header() walks the root directory of a .wtv into a 1024-byte parsebuf
and trusts two length fields out of the file:

  * len (uint16) counts the 32-byte record as well, but only the upper
    bound was checked, so len < 32 made len - 32 wrap round in the size_t
    that buffered_read() takes for its count;

  * text_len (uint32) is a character count for the UTF-16 name that starts
    8 bytes into the body. Nothing tied it to the body that was actually
    read, so the conversion loop walks off parsebuf, and at UINT32_MAX
    malloc(text_len + 1) wraps to malloc(0) while string[text_len] still
    writes ~4 GB past it. The .entries. branch then reads 8 bytes further
    still.

Reject len < 32 the way wtv_len_plausible() already does for the same
field, keep the body length around, and require the string and the value
that follows it to fit in it. Also free parsebuf on the "Missing WTV
header" path, which was the one error return in this function that leaked
it.

A 4 KB crafted file (.wtv is recognised from its first four bytes alone)
segfaults in read_header on an ASan build before this change and is
rejected cleanly after it.

Fixes #2433

Co-authored-by: pranayr710 <Pranay@nordictechdesign.com>
2026-11-10 07:28:39 -08:00
Aditya Saroha
14fa9301d6 [FIX] GXF: bound cc_count and footer read in parse_ad_cdp (#2425) (#2439) 2026-11-10 07:27:48 -08:00
harshal
9a7a354ea7 [FIX] Skip malformed SCC hex words without aborting (#2451)
* [FIX] Reject non-hex SCC words before slicing

* Remove unused SCC sample file

No test reads tests/samples/scc_unicode_token.scc; the unit tests use
inline content.

---------

Co-authored-by: harshalsp07 <222931229+harshalsp07@users.noreply.github.com>
Co-authored-by: Carlos Fernandez <carlos@sanz.dev>
2026-11-10 07:20:52 -08:00
Arman Thakur
dc964e1022 Reject malformed --service all values instead of aborting (#2405)
parse_708_services() took the charset of "all[X]" by slicing the value
from byte 4 to one before the end whenever it was longer than "all".
It never checked for the brackets, so:

- "all1" and "all[" panicked (the range starts at 4 but ends at 3),
  and "allé" panicked slicing inside a character. The panic can't
  unwind out of ccxr_parse_parameters, so the process aborted
  (SIGABRT, exit 134).
- "all[EUC-KR" lost its last letter and failed later in iconv with
  charset "EUC-K"; "allEUC-KR]" became "UC-KR".

This came with the Rust parser (#1619). The C parser only took a
charset when the value was longer than "all[]", so it never panicked,
though it did not check the brackets either.

Accept "all" and "all[charset]" only, and report anything else as a
malformed parameter (exit 7), as #2393 does for service numbers.
2026-11-10 07:18:59 -08:00
Bishwa Saha
becc0f74bb Fix C0/C1 PMT length underflow in parse_PMT (#2420)
parse_PMT() strips a leading SCTE 57 Program Information or Program
Name table (table_id 0xC0/0xC1) before parsing the PMT that follows.
The 12-bit c0length comes from the stream, but it was subtracted from
len and passed to memmove() without checking that the section fits in
the buffered payload. When c0length + 3 exceeded len, the size wrapped
to a huge value and memmove() read and wrote far past the PSI buffer.

Reject the section when it does not fit, and subtract the skipped
prefix from len so the remaining checks and loops use the bytes that
are actually buffered.
2026-11-10 07:17:33 -08:00
Pratham Jaiswal
f8ca0eccce fix(dvb): bound language count and correct descriptor stride (#2418)
parse_dvb_description() derived the language count from the descriptor
length byte without limiting it to the size of the dvb_config arrays, and
advanced the read cursor by a growing stride instead of a fixed entry
width.

- Clamp n_language to MAX_LANGUAGE_PER_DESC after the existing warning.
  Previously a descriptor longer than 40 bytes made the loop write past
  lang_index/sub_type/composition_id/ancillary_id, which are each five
  elements, corrupting the caller's stack frame in parse_PMT().
- Change the loop increment from data_ptr += i * 8 to data_ptr += 8.
  Because the comma operator evaluates i++ before the increment, the old
  form advanced the cursor quadratically (4*i*(i+1) bytes) and read past
  the descriptor buffer from the ninth entry onwards.

Verified with an AddressSanitizer build of this translation unit: a
248-byte descriptor (n_language = 31) produced a stack-buffer-overflow
write at the ancillary_id[6] store before the change and no diagnostics
after it, with n_language clamped to 5.
2026-11-10 07:14:35 -08:00
Chandragupt Singh
185fe3f127 [FIX] ci: pin Linux build and format runners to ubuntu-24.04 (#2428) 2026-11-09 17:09:50 -08:00
Carlos Fernandez Sanz
d7eb132e15 Fail cleanly when a CEA-708 file can't be created (#2396)
screen_print() unwrapped the result of writer_output(), so a per-service
CEA-708 output file that couldn't be created aborted the run with a
panic (SIGABRT). -o /dev/null hits this, since the service file becomes
/dev/null.p1.svc01.srt; so does anything that makes the file
unwritable.

The C writer, and v0.94 before the port, treat this as a fatal
file-creation error (exit 5). Do the same, and include the file name
in the error, which previously carried only the OS message.
2026-10-17 22:01:51 -07:00
Carlos Fernandez Sanz
4425c04f29 [FIX] Process each RCWT input as its own stream (#2395)
* Drop the previous file's bytes when opening a file

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.

* Process each RCWT input as its own stream

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.
2026-10-17 21:50:53 -07:00
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