Skip to content

Commit 0b1a967

Browse files
cfsmp3claude
andauthored
fix: prevent stream detection from corrupting current_file index (#2209)
detect_stream_type() reads up to 1MB (STARTBYTESLENGTH) via buffered_read_opt() for format detection. For input files smaller than 1MB, the read hits EOF and—because binary_concat defaults to enabled—buffered_read_opt() calls switch_to_next_file(). This increments current_file past the valid range and closes the file descriptor, leaving format-specific handlers (matroska_loop, MP4, etc.) to crash when they access inputfile[current_file]. Fix: temporarily disable binary_concat around detect_stream_type() so that hitting EOF during detection never triggers file switching. Fixes the root cause of the crash reported in PR #2206 (which proposed a band-aid of using current_file-1). Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 52b5385 commit 0b1a967

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/lib_ccx/ccx_demuxer.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,19 @@ static int ccx_demuxer_open(struct ccx_demuxer *ctx, const char *file)
136136

137137
if (ctx->auto_stream == CCX_SM_AUTODETECT)
138138
{
139+
// Temporarily disable binary_concat during stream detection.
140+
// detect_stream_type reads up to 1MB (STARTBYTESLENGTH) via
141+
// buffered_read_opt. For files smaller than 1MB, hitting EOF
142+
// causes buffered_read_opt to call switch_to_next_file (when
143+
// binary_concat is enabled), which increments current_file
144+
// past the valid range and closes the file descriptor.
145+
// This leaves current_file pointing beyond inputfile[], causing
146+
// format-specific handlers (e.g. matroska_loop) to crash when
147+
// they access inputfile[current_file].
148+
int saved_binary_concat = ccx_options.binary_concat;
149+
ccx_options.binary_concat = 0;
139150
detect_stream_type(ctx);
151+
ccx_options.binary_concat = saved_binary_concat;
140152
switch (ctx->stream_mode)
141153
{
142154
case CCX_SM_ELEMENTARY_OR_NOT_FOUND:

0 commit comments

Comments
 (0)