Skip to content

Commit 72cbc7d

Browse files
committed
Fix infinite loop by skipping unexpected start codes in MPEG-2 parsing (Issue #1754)
1 parent 45ee03a commit 72cbc7d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/lib_ccx/es_functions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ static int es_video_sequence(struct encoder_ctx *enc_ctx, struct lib_cc_decode *
324324
else
325325
{
326326
mprint("\nUnexpected startcode: %02X\n", startcode);
327+
skip_u32(esstream);
327328
}
328329
dec_ctx->no_bitstream_error = 0;
329330
return 0;

src/lib_ccx/general_loop.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,13 @@ int process_non_multiprogram_general_loop(struct lib_ccx_ctx *ctx,
10291029
}
10301030
}
10311031
size_t got = process_m2v(*enc_ctx, dec_ctx_video, data_node_video->buffer, data_node_video->len, dec_sub_video);
1032+
if (got == 0 && data_node_video->len >= 1048576)
1033+
{
1034+
// Prevent infinite loop if decoder consumes nothing from a very large buffer (1MB)
1035+
// This handles cases where process_m2v returns 0 (error or no progress) but buffer is full
1036+
// We use a large threshold to ensure we don't discard valid video data that is just waiting for more bytes.
1037+
got = data_node_video->len;
1038+
}
10321039
if (got > 0)
10331040
{
10341041
memmove(data_node_video->buffer, data_node_video->buffer + got, (size_t)(data_node_video->len - got));

0 commit comments

Comments
 (0)