From 877df4850d83dfe744cf334432476152cfe22ff4 Mon Sep 17 00:00:00 2001 From: Vishnu Srivatsava Date: Tue, 27 Oct 2026 00:31:35 +0530 Subject: [PATCH] [FIX] rcwt_loop: decide teletext mode once from the file header 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. --- src/lib_ccx/general_loop.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib_ccx/general_loop.c b/src/lib_ccx/general_loop.c index 9de33aa77..84bef766b 100644 --- a/src/lib_ccx/general_loop.c +++ b/src/lib_ccx/general_loop.c @@ -1711,6 +1711,7 @@ int rcwt_loop(struct lib_ccx_ctx *ctx) struct encoder_ctx *enc_ctx = update_encoder_list(ctx); struct TeletextCtx *telctx; int saved_binary_concat; + int is_teletext; // As BUFSIZE is a macro this is just a reminder if (BUFSIZE < (3 * 0xFFFF + 10)) fatal(CCX_COMMON_EXIT_BUG_BUG, "In rcwt_loop: BUFSIZE too small for RCWT caption block.\n"); @@ -1771,7 +1772,11 @@ int rcwt_loop(struct lib_ccx_ctx *ctx) #else dec_ctx->dtvcc->encoder = (void *)enc_ctx; // WARN: otherwise cea-708 will not work #endif - if (parsebuf[6] == 0 && parsebuf[7] == 2) + // The file header decides the mode once: parsebuf is reused for data + // headers and caption blocks below, so re-reading it per iteration could + // route 608 caption data into the teletext decoder (whose context is NULL). + is_teletext = (parsebuf[6] == 0 && parsebuf[7] == 2); + if (is_teletext) { dec_ctx->codec = CCX_CODEC_TELETEXT; dec_ctx->private_data = telxcc_init(); @@ -1789,7 +1794,7 @@ int rcwt_loop(struct lib_ccx_ctx *ctx) // Loop until no more data is found while (1) { - if (parsebuf[6] == 0 && parsebuf[7] == 2) + if (is_teletext) { result = buffered_read(ctx->demux_ctx, buf, TELETEXT_CHUNK_LEN); ctx->demux_ctx->past += result;