diff --git a/src/lib_ccx/stream_functions.c b/src/lib_ccx/stream_functions.c index 9f6000fa..e83e4f1f 100644 --- a/src/lib_ccx/stream_functions.c +++ b/src/lib_ccx/stream_functions.c @@ -295,6 +295,13 @@ int read_video_pes_header(struct ccx_demuxer *ctx, struct demuxer_data *data, un // Read the next video PES // ((nextheader[3]&0xf0)==0xe0) long long result; + + // A caller-supplied buffer must hold the PES length and nextheader[6] + // before either is read; a truncated packet can leave fewer bytes. + if (sbuflen > 0 && sbuflen < 7) + { + return -1; + } unsigned peslen = nextheader[4] << 8 | nextheader[5]; unsigned payloadlength = 0; // Length of packet data bytes static LLONG current_pts_33 = 0; // Last PTS from the header, without rollover bits diff --git a/src/lib_ccx/ts_tables.c b/src/lib_ccx/ts_tables.c index 2874ecbd..82ccc382 100644 --- a/src/lib_ccx/ts_tables.c +++ b/src/lib_ccx/ts_tables.c @@ -985,7 +985,9 @@ void parse_SDT(struct ccx_demuxer *ctx) // | payload_start[4]); // unsigned version_number = (payload_start[5] & 0x3E) >> 1; - if (section_length > payload_length - 4) + // 12 is the smallest legal section: 8 bytes of fields plus the CRC. + // Anything shorter would make the services loop length below underflow. + if (section_length < 12 || section_length > payload_length - 4) { return; }