From 09a265cf0cb48d31caa11753dda712bb4231e90b Mon Sep 17 00:00:00 2001 From: Francois Cartegnie Date: Fri, 18 Nov 2022 10:53:00 +0100 Subject: [PATCH] demux: ts: flag truncation as corruption --- modules/demux/mpeg/ts_pes.c | 9 +++++++-- test/modules/demux/ts_pes.c | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/demux/mpeg/ts_pes.c b/modules/demux/mpeg/ts_pes.c index bbb0f8ad7e..bd7096e62f 100644 --- a/modules/demux/mpeg/ts_pes.c +++ b/modules/demux/mpeg/ts_pes.c @@ -193,6 +193,11 @@ bool ts_pes_Gather( ts_pes_parse_callback *cb, /* On dropped blocks discontinuity */ else if( p_pkt->i_flags & BLOCK_FLAG_DISCONTINUITY ) { + /* If we know the final size and didn't gather enough bytes it is corrupted + or if the discontinuity doesn't carry the start code */ + if( p_pes->gather.i_gathered && (p_pes->gather.i_data_size || + (b_aligned_ts_payload && !b_unit_start) ) ) + p_pes->gather.i_block_flags |= BLOCK_FLAG_CORRUPTED; b_ret |= ts_pes_Push( cb, p_pes, NULL, true, i_append_pcr ); /* it can't match the target size and need to resync on sync code */ @@ -201,8 +206,8 @@ bool ts_pes_Gather( ts_pes_parse_callback *cb, p_pes->gather.i_saved = 0; /* Propagate to output block to notify packetizers/decoders */ if( p_pes->p_es ) - p_pes->p_es->i_next_block_flags |= BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED; - p_pes->gather.i_block_flags|= BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED; + p_pes->p_es->i_next_block_flags |= BLOCK_FLAG_DISCONTINUITY; + p_pes->gather.i_block_flags|= BLOCK_FLAG_DISCONTINUITY; } if ( unlikely(p_pes->gather.i_saved > 0) ) diff --git a/test/modules/demux/ts_pes.c b/test/modules/demux/ts_pes.c index be30ff8124..ac88a59dbb 100644 --- a/test/modules/demux/ts_pes.c +++ b/test/modules/demux/ts_pes.c @@ -280,8 +280,9 @@ int main() block_ChainProperties(output, &outputcount, &outputsize, NULL); ASSERT(outputcount == 2); ASSERT(outputsize == sizeof(aligned1) * 2 - 1); + ASSERT(output->i_flags & BLOCK_FLAG_CORRUPTED); /* First block is corrupted 15/16 bytes */ ASSERT((output->i_flags & BLOCK_FLAG_DISCONTINUITY) == 0); - ASSERT(output->p_next->i_flags & BLOCK_FLAG_DISCONTINUITY); /* Next block resumes as discont */ + ASSERT(output->p_next->i_flags == BLOCK_FLAG_DISCONTINUITY); /* Next block resumes as discont */ RESET; PKT_FROM(aligned1); @@ -295,6 +296,7 @@ int main() block_ChainProperties(output, &outputcount, &outputsize, NULL); ASSERT(outputcount == 1); ASSERT(outputsize == sizeof(aligned1)); + //ASSERT(output->i_flags == BLOCK_FLAG_CORRUPTED); /* First might be corrupted but we don't really know */ RESET; return 0;