Skip to content

Commit

Permalink
fix: #367 mpeg4 es rtp deserialize au length check
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Dec 28, 2024
1 parent 87d503b commit 1c16e21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions librtp/payload/rtp-mpeg4-generic-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ static int rtp_mpeg4_generic_pack_input(void* pack, const void* data, int bytes,
// SDP fmtp: mode=AAC-hbr;sizeLength=13;indexLength=3;indexDeltaLength=3;
header[0] = 0;
header[1] = 16; // 16-bits AU headers-length
// When the AU-size is associated with an AU fragment, the AU size indicates
// the size of the entire AU and not the size of the fragment.
// This can be exploited to determine whether a
// packet contains an entire AU or a fragment, which is particularly
// useful after losing a packet carrying the last fragment of an AU.
header[2] = (uint8_t)(size >> 5);
header[3] = (uint8_t)(size & 0x1f) << 3;

Expand Down
17 changes: 12 additions & 5 deletions librtp/payload/rtp-mpeg4-generic-unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ static int rtp_decode_mpeg4_generic(void* p, const void* packet, int bytes)
size = size >> 3; // bit -> byte
if (pau + size > pend)
{
assert(0);
//helper->size = 0;
helper->lost = 1;
//helper->flags |= RTP_PAYLOAD_FLAG_PACKET_LOST;
return -1; // invalid packet
// fragment ?
assert(1 == au_numbers);
pkt.payload = pau;
pkt.payloadlen = size;
rtp_payload_write(helper, &pkt);
return 1;
}

// TODO: add ADTS/ASC ???
Expand All @@ -74,6 +75,12 @@ static int rtp_decode_mpeg4_generic(void* p, const void* packet, int bytes)

if (au_numbers > 1 || pkt.rtp.m)
{
if (helper->size != size)
{
//helper->size = 0;
helper->lost = 1;
//helper->flags |= RTP_PAYLOAD_FLAG_PACKET_LOST;
}
rtp_payload_onframe(helper);
}
}
Expand Down

0 comments on commit 1c16e21

Please sign in to comment.