Guard two more short-payload reads in TS parsing

Both were found while verifying #2349 and are reachable from stream
data:

- parse_SDT passes section_length - 4 - 8 to the services loop, and
  section_length comes from the stream. Below 12 (the smallest legal
  section: 8 bytes of fields plus the CRC) the unsigned subtraction
  wraps and the loop reads past the buffer. It got past both existing
  length checks.

- read_video_pes_header reads the PES length and nextheader[6] before
  its own sbuflen < 9 check. With #2349 stopping the earlier crash in
  ts_readstream, a capbuf holding only a 3-byte start code now reaches
  it when flushed at EOF and is read past its end. Return -1 for a
  caller buffer shorter than 7 bytes, as the < 9 path already does.
This commit is contained in:
Carlos Fernandez
2026-10-11 08:27:50 -07:00
parent cde38d1070
commit a4e0055704
2 changed files with 10 additions and 1 deletions

View File

@@ -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

View File

@@ -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;
}