From f4dfd31d9827eef9107165e8d3d050d1e0f91f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Bov=C3=A9e?= Date: Wed, 9 Sep 2020 12:48:58 +0200 Subject: [PATCH] Bugfix: prevent borked generated audio file if meetecho header is present with no RTP data next --- postprocessing/janus-pp-rec.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/postprocessing/janus-pp-rec.c b/postprocessing/janus-pp-rec.c index f87b9f9d131..0a886b84684 100644 --- a/postprocessing/janus-pp-rec.c +++ b/postprocessing/janus-pp-rec.c @@ -632,6 +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; /* Start loop */ while(working && offset < fsize) { /* Read frame header */ @@ -679,6 +680,10 @@ int main(int argc, char *argv[]) /* Things are simpler for data, no reordering is needed: start by the data time */ gint64 when = 0; bytes = fread(&when, sizeof(gint64), 1, file); + if (bytes < 1) { + JANUS_LOG(LOG_WARN, "Missing data header timestamp"); + break; + } when = ntohll(when); offset += sizeof(gint64); len -= sizeof(gint64); @@ -709,7 +714,12 @@ int main(int argc, char *argv[]) continue; } /* Only read RTP header */ - bytes = fread(prebuffer, sizeof(char), len > 24 ? 24: len, file); + rtp_header_len = len > 24 ? 24: len; + 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); + break; + } janus_pp_rtp_header *rtp = (janus_pp_rtp_header *)prebuffer; JANUS_LOG(LOG_VERB, " -- RTP packet (ssrc=%"SCNu32", pt=%"SCNu16", ext=%"SCNu16", seq=%"SCNu16", ts=%"SCNu32")\n", ntohl(rtp->ssrc), rtp->type, rtp->extension, ntohs(rtp->seq_number), ntohl(rtp->timestamp));