Skip to content

Commit a3e5ae8

Browse files
author
Dhanush Varma
committed
fix: crash when reading from stdin with no data
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().
1 parent 9f250b1 commit a3e5ae8

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/lib_ccx/general_loop.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ int general_loop(struct lib_ccx_ctx *ctx)
15071507
if (!data_node)
15081508
continue;
15091509
}
1510-
if (ctx->live_stream)
1510+
if (ctx->live_stream && dec_ctx)
15111511
{
15121512
LLONG t = get_fts(dec_ctx->timing, dec_ctx->current_field);
15131513
if (!t && ctx->demux_ctx->global_timestamp_inited)
@@ -1574,7 +1574,8 @@ int general_loop(struct lib_ccx_ctx *ctx)
15741574
}
15751575

15761576
// void segment_output_file(struct lib_ccx_ctx *ctx, struct lib_cc_decode *dec_ctx);
1577-
segment_output_file(ctx, dec_ctx);
1577+
if (dec_ctx)
1578+
segment_output_file(ctx, dec_ctx);
15781579

15791580
if (ccx_options.send_to_srv)
15801581
net_check_conn();

src/rust/src/file_functions/file.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,11 @@ pub unsafe fn switch_to_next_file(
161161
}
162162

163163
// 2. Handle special input sources
164-
#[allow(deref_nullptr)]
165164
match ccx_options.input_source {
166165
DataSource::Stdin | DataSource::Network | DataSource::Tcp => {
167-
demux_ctx.open(*ptr::null(), ccx_options);
168-
return match ret {
169-
r if r < 0 => 0,
170-
r if r > 0 => r,
171-
_ => 1,
172-
};
166+
// For stdin/network/tcp, the fd is set up in demux_ctx.open()
167+
// called from the main loop. Here we just need to signal success.
168+
return 1;
173169
}
174170
_ => {}
175171
}

0 commit comments

Comments
 (0)