Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RTP header buffer read #2411

Merged
merged 3 commits into from
Oct 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions postprocessing/janus-pp-rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ int main(int argc, char *argv[])
times_resetted = 0;
post_reset_pkts = 0;
uint64_t max32 = UINT32_MAX;
uint16_t rtp_header_len;
uint16_t rtp_header_len, rtp_read_n;
/* Start loop */
while(working && offset < fsize) {
/* Read frame header */
Expand Down Expand Up @@ -714,7 +714,7 @@ int main(int argc, char *argv[])
continue;
}
/* Only read RTP header */
rtp_header_len = len > 24 ? 24: len;
rtp_header_len = 12;
bytes = fread(prebuffer, sizeof(char), rtp_header_len, file);
if(bytes < rtp_header_len) {
JANUS_LOG(LOG_WARN, "Missing RTP packet header data (%d instead %"SCNu16")\n", bytes, rtp_header_len);
Expand All @@ -727,13 +727,33 @@ int main(int argc, char *argv[])
JANUS_LOG(LOG_VERB, " -- -- Skipping CSRC list\n");
skip += rtp->csrccount*4;
}
if(rtp->csrccount || rtp->extension) {
rtp_read_n = (rtp->csrccount + rtp->extension)*4;
bytes = fread(prebuffer+rtp_header_len, sizeof(char), rtp_read_n, file);
if(bytes < rtp_read_n) {
JANUS_LOG(LOG_WARN, "Missing RTP packet header data (%d instead %"SCNu16")\n",
rtp_header_len+bytes, rtp_header_len+rtp_read_n);
break;
} else {
rtp_header_len += rtp_read_n;
}
}
audiolevel = -1;
rotation = -1;
if(rtp->extension) {
janus_pp_rtp_header_extension *ext = (janus_pp_rtp_header_extension *)(prebuffer+12+skip);
JANUS_LOG(LOG_VERB, " -- -- RTP extension (type=0x%"PRIX16", length=%"SCNu16")\n",
ntohs(ext->type), ntohs(ext->length));
skip += 4 + ntohs(ext->length)*4;
rtp_read_n = ntohs(ext->length)*4;
skip += 4 + rtp_read_n;
bytes = fread(prebuffer+rtp_header_len, sizeof(char), rtp_read_n, file);
if(bytes < rtp_read_n) {
JANUS_LOG(LOG_WARN, "Missing RTP packet header data (%d instead %"SCNu16")\n",
rtp_header_len+bytes, rtp_header_len+rtp_read_n);
break;
} else {
rtp_header_len += rtp_read_n;
}
if(audio_level_extmap_id > 0)
janus_pp_rtp_header_extension_parse_audio_level(prebuffer, len, audio_level_extmap_id, &audiolevel);
if(video_orient_extmap_id > 0) {
Expand Down