CCExtractor: stack out-of-bounds write and quadratic out-of-bounds read in the DVB subtitle descriptor parser (parse_dvb_description)

Open
#2,417 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 7 days

@kanaseprathamesh568-a11y is already working on this.

Since Nov 12, 2026.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c
Domain
backend, security

Research direction

Read the linked technical write-up for the exact file, line, reachability chain, and suggested fix; trace from the public entry point to parse_dvb_description. Then review the parser’s bounds handling and add or run focused tests for the reported out-of-bounds read and write. Done means the parser handles the described input without either memory-safety error.

Written by the indexing model from the issue text.

Description

Hello, and thank you for maintaining this project.

I found a likely memory-safety issue by static source review (no runtime exploit was developed). The technical details are inline below so this report is self-contained, with a full write-up linked within.

Affected component: CCExtractor, the DVB subtitle descriptor parser parse_dvb_description() in src/lib_ccx/dvb_subtitle_decoder.c, reached from the MPEG-TS PMT parser parse_PMT() in src/lib_ccx/ts_tables.c

Tested version(s): Release v0.96.6, release commit 185631dcb0217b4ad09d43009cb69f0593996a5d. The identical vulnerable code is on master HEAD 97a0d24832174a4d7f82f7f7901e8f785dd2c406. Reviewed statically at the pinned commit, no live deployment was contacted.

Details:

CCExtractor parses the DVB subtitling_descriptor (tag 0x59) out of the Program Map Table of an MPEG transport stream in parse_dvb_description() (src/lib_ccx/dvb_subtitle_decoder.c). The one-byte descriptor length reaches the function as len, and the function derives n_language = len / 8 (range 0 to 31), then loops n_language times writing four fixed arrays and advancing a read cursor. There are two defects in the same loop. A crafted .ts file reaches this code under the default configuration.

Reachability (all C, not gated out in the default build): ts_get_more_data (ts_functions.c:1086) calls ts_readstream (ts_functions.c:759) which calls parse_PMT (call at ts_functions.c:844). For an elementary stream of type CCX_STREAM_TYPE_PRIVATE_MPEG2 (0x06), parse_PMT walks the ES descriptor loop (ts_tables.c:354) and for descriptor tag CCX_MPEG_DSC_DVB_SUBTITLE (0x59, ts_tables.c:385) declares a stack local struct dvb_config cnf (ts_tables.c:387) and calls parse_dvb_description(&cnf, es_info, desc_len) (ts_tables.c:399). desc_len is the raw descriptor length byte (ts_tables.c:362), validated only to fit inside the PMT buffer (ts_tables.c:365). The #ifndef ENABLE_OCR skip is compiled out in the official build (linux/build adds -DENABLE_OCR), and IS_FEASIBLE(codec, nocodec, CCX_CODEC_DVB) is true under the default codec=CCX_CODEC_ANY, nocodec=CCX_CODEC_NONE (ccx_common_option.c:120-121, macro at ccx_common_constants.h:314). CCExtractor has ported the 608 and 708 caption decoders to Rust, but the TS demuxer, PMT parser and DVB subtitle decoder remain C with no Rust replacement.

FINDING 1, stack out-of-bounds write (CWE-787, CWE-121 stack-based buffer overflow). dvb_subtitle_decoder.h defines MAX_LANGUAGE_PER_DESC as 5 and sizes lang_index, sub_type, composition_id and ancillary_id each at 5 elements, so struct dvb_config is 52 bytes. parse_dvb_description computes n_language = len/8 up to 31 and the overflow check at dvb_subtitle_decoder.c:2019 only prints a warning, it never clamps. The loop at :2025 writes cfg->lang_index[i], cfg->sub_type[i], cfg->composition_id[i] and cfg->ancillary_id[i] for i up to n_language-1 (up to 30). The first write past the 52-byte struct is ancillary_id[6] at offset 52, reached when the length byte is 56 (n_language 7). A length byte of 248 (n_language 31) writes up to lang_index[30] at offset 124, about 72 bytes past the struct. Because cnf is a stack local in parse_PMT, this is a stack-based buffer overflow. For a length byte of 248 the writes at indices 6 and 7 use fully in-bounds descriptor reads, so two 16-bit values just past the struct (composition_page_id and ancillary_page_id) are directly attacker-controlled. Fix: clamp cfg->n_language to MAX_LANGUAGE_PER_DESC.

FINDING 2, out-of-bounds read via a quadratic pointer stride (CWE-125). The loop increment at dvb_subtitle_decoder.c:2025 is data_ptr += i * 8, and because the comma operator evaluates i++ first, the read cursor advances by 4i(i+1) bytes instead of the intended 8 per language entry (offsets 0, 8, 24, 48, 80, 120, 168, 224, 288, ...). The body reads data_ptr[0..7] at :2033 and :2045-2047. The descriptor buffer holds only 8*n_language bytes, so the reads run past the descriptor into the rest of the PMT PID buffer on the heap (for a length byte of 248 the reads leave the descriptor at index 8, offset 288). The over-read bytes become the values that FINDING 1 writes. Fix: change the increment to data_ptr += 8.

Impact: a crafted MPEG transport stream parsed under default config corrupts the stack frame of parse_PMT with partly attacker-controlled bytes and over-reads the heap, which leads to a crash. On a stack-protector build the overflow toward the return address trips the canary and aborts. Instruction-pointer control, a general write-what-where, an information leak back to the attacker, and code execution are not established.

Verification: this was confirmed by static review of the pinned released source. The attacker-controlled length byte, the missing clamp, the quadratic stride, the fixed 5-element arrays, the stack location of the target struct, and default-config reachability are all visible in the cited source. No request was executed against a live deployment and no AddressSanitizer run was performed in this phase, so the exact faulting offset is inferred from the source path. A negative control is a DVB subtitle descriptor whose length byte is 8, 16, 24, 32 or 40 (n_language 1 to 5), which keeps all array writes in bounds.

Write-up with full code trace, attack flow, a PoC transport-stream builder and the fix diff: https://hackmd.io/@haindpwn/ccextractor-parse-dvb-description-stack-oob-write

Reported by HaiND (Nguyen Dinh Hai), Post and Telecommunication Institute of Technology, github.com/Haind03.

Dominant language
C
Stars
919
Forks
604
Avg merge
13d 12h
Merged PRs (30d)
7

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from CCExtractor/ccextractor

All issues in CCExtractor/ccextractor

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.