mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-04-05 21:51:23 +00:00
fix: crash when reading from stdin with no data (#2210)
Two bugs: (1) general_loop.c dereferences NULL dec_ctx in the live_stream progress code when no data was processed. (2) Rust switch_to_next_file calls demux_ctx.open() for stdin, triggering null pointer dereference via ptr::null(). Fix: add NULL check for dec_ctx in general_loop.c, and return early from switch_to_next_file for stdin/network/tcp sources instead of calling demux_ctx.open(). Co-authored-by: Dhanush Varma <your@email.com>
This commit is contained in:
@@ -1516,7 +1516,7 @@ int general_loop(struct lib_ccx_ctx *ctx)
|
||||
if (!data_node)
|
||||
continue;
|
||||
}
|
||||
if (ctx->live_stream)
|
||||
if (ctx->live_stream && dec_ctx)
|
||||
{
|
||||
LLONG t = get_fts(dec_ctx->timing, dec_ctx->current_field);
|
||||
if (!t && ctx->demux_ctx->global_timestamp_inited)
|
||||
@@ -1583,7 +1583,9 @@ int general_loop(struct lib_ccx_ctx *ctx)
|
||||
}
|
||||
|
||||
// void segment_output_file(struct lib_ccx_ctx *ctx, struct lib_cc_decode *dec_ctx);
|
||||
segment_output_file(ctx, dec_ctx);
|
||||
// dec_ctx is NULL only when no data was processed (e.g. empty stdin)
|
||||
if (dec_ctx)
|
||||
segment_output_file(ctx, dec_ctx);
|
||||
|
||||
if (ccx_options.send_to_srv)
|
||||
net_check_conn();
|
||||
|
||||
@@ -152,8 +152,6 @@ pub unsafe fn switch_to_next_file(
|
||||
bytes_in_buffer: i64,
|
||||
ccx_options: &mut Options,
|
||||
) -> i32 {
|
||||
let mut ret = 0;
|
||||
|
||||
// 1. Initially reset condition
|
||||
let mut demux_ctx = copy_demuxer_from_c_to_rust(ctx.demux_ctx);
|
||||
if ctx.current_file == -1 || !ccx_options.binary_concat {
|
||||
@@ -161,19 +159,18 @@ pub unsafe fn switch_to_next_file(
|
||||
}
|
||||
|
||||
// 2. Handle special input sources
|
||||
#[allow(deref_nullptr)]
|
||||
match ccx_options.input_source {
|
||||
DataSource::Stdin | DataSource::Network | DataSource::Tcp => {
|
||||
demux_ctx.open(*ptr::null(), ccx_options);
|
||||
return match ret {
|
||||
r if r < 0 => 0,
|
||||
r if r > 0 => r,
|
||||
_ => 1,
|
||||
};
|
||||
// stdin/network/tcp don't use file-based switching.
|
||||
// Return success immediately — fd is configured in the main open() path.
|
||||
return 1;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
#[allow(unused_assignments)]
|
||||
let mut ret = 0;
|
||||
|
||||
// 3. Close current file handling
|
||||
|
||||
if demux_ctx.is_open() {
|
||||
|
||||
Reference in New Issue
Block a user