Skip to content

Commit 7c14581

Browse files
committed
avformat/whip: fix srtcp buffer crosses boundary
whip->buf size is 4096 rather than srtcp_len, srtcp data just use part of its memory, handle it need more logic. So allocate a temporary pkt to carry the SRTCP data Signed-off-by: Jack Lau <jacklau1222@qq.com>
1 parent fe8c500 commit 7c14581

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

libavformat/whip.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,16 +1948,18 @@ static int whip_write_packet(AVFormatContext *s, AVPacket *pkt)
19481948
int i = 0;
19491949
/* SRTCP index(4 bytes) + HMAC (SRTP_AES128_CM_SHA1_80 10bytes) */
19501950
int srtcp_len = len + 4 + 10;
1951-
int ret = ff_srtp_decrypt(&whip->srtp_recv, whip->buf, &srtcp_len);
1951+
uint8_t *pkt = av_malloc(srtcp_len);
1952+
memcpy(pkt, whip->buf, srtcp_len);
1953+
int ret = ff_srtp_decrypt(&whip->srtp_recv, pkt, &srtcp_len);
19521954
if (ret < 0)
19531955
av_log(whip, AV_LOG_ERROR, "WHIP: SRTCP decrypt failed: %d\n", ret);
19541956
while (12 + i < len && ret >= 0) {
19551957
/**
19561958
* See https://datatracker.ietf.org/doc/html/rfc4585#section-6.1
19571959
* Handle multi NACKs in bundled packet.
19581960
*/
1959-
uint16_t pid = AV_RB16(&whip->buf[ptr + 12 + i]);
1960-
uint16_t blp = AV_RB16(&whip->buf[ptr + 14 + i]);
1961+
uint16_t pid = AV_RB16(&pkt[ptr + 12 + i]);
1962+
uint16_t blp = AV_RB16(&pkt[ptr + 14 + i]);
19611963

19621964
/* retransmit pid + any bit set in blp */
19631965
for (int bit = -1; bit < 16; bit++) {
@@ -1967,13 +1969,16 @@ static int whip_write_packet(AVFormatContext *s, AVPacket *pkt)
19671969

19681970
const RtpHistoryItem * it = rtp_history_find(whip, seq);
19691971
if (it) {
1970-
// send_rtx_packet(s, it->pkt, it->size);
1972+
send_rtx_packet(s, it->pkt, it->size);
19711973
av_log(whip, AV_LOG_INFO, "WHIP: NACK packet found: size: %d, seq=%d, blp=%d\n", it->size, seq, blp);
1972-
} else
1973-
av_log(whip, AV_LOG_INFO, "WHIP: NACK packet, seq=%d, blp=%d, not found, the latest packet seq: %d\n", seq, blp, whip->history[whip->hist_head-1].seq);
1974+
} else {
1975+
av_log(whip, AV_LOG_INFO, "WHIP: NACK packet, seq=%d, blp=%d, not found, the latest packet seq: %d, rtx seq: %d\n",
1976+
seq, blp, whip->history[whip->hist_head-1].seq, whip->rtx_seq);
1977+
}
19741978
}
19751979
i = i + 4;
19761980
}
1981+
av_free(pkt);
19771982
}
19781983
}
19791984
}

0 commit comments

Comments
 (0)