Skip to content

Commit 34b5479

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 3eaedf7 commit 34b5479

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
@@ -1942,16 +1942,18 @@ static int whip_write_packet(AVFormatContext *s, AVPacket *pkt)
19421942
int i = 0;
19431943
/* SRTCP index(4 bytes) + HMAC (SRTP_AES128_CM_SHA1_80 10bytes) */
19441944
int srtcp_len = len + 4 + 10;
1945-
int ret = ff_srtp_decrypt(&whip->srtp_recv, whip->buf, &srtcp_len);
1945+
uint8_t *pkt = av_malloc(srtcp_len);
1946+
memcpy(pkt, whip->buf, srtcp_len);
1947+
int ret = ff_srtp_decrypt(&whip->srtp_recv, pkt, &srtcp_len);
19461948
if (ret < 0)
19471949
av_log(whip, AV_LOG_ERROR, "WHIP: SRTCP decrypt failed: %d\n", ret);
19481950
while (12 + i < len && ret >= 0) {
19491951
/**
19501952
* See https://datatracker.ietf.org/doc/html/rfc4585#section-6.1
19511953
* Handle multi NACKs in bundled packet.
19521954
*/
1953-
uint16_t pid = AV_RB16(&whip->buf[ptr + 12 + i]);
1954-
uint16_t blp = AV_RB16(&whip->buf[ptr + 14 + i]);
1955+
uint16_t pid = AV_RB16(&pkt[ptr + 12 + i]);
1956+
uint16_t blp = AV_RB16(&pkt[ptr + 14 + i]);
19551957

19561958
/* retransmit pid + any bit set in blp */
19571959
for (int bit = -1; bit < 16; bit++) {
@@ -1961,13 +1963,16 @@ static int whip_write_packet(AVFormatContext *s, AVPacket *pkt)
19611963

19621964
const RtpHistoryItem * it = rtp_history_find(whip, seq);
19631965
if (it) {
1964-
// send_rtx_packet(s, it->pkt, it->size);
1966+
send_rtx_packet(s, it->pkt, it->size);
19651967
av_log(whip, AV_LOG_INFO, "WHIP: NACK packet found: size: %d, seq=%d, blp=%d\n", it->size, seq, blp);
1966-
} else
1967-
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);
1968+
} else {
1969+
av_log(whip, AV_LOG_INFO, "WHIP: NACK packet, seq=%d, blp=%d, not found, the latest packet seq: %d, rtx seq: %d\n",
1970+
seq, blp, whip->history[whip->hist_head-1].seq, whip->rtx_seq);
1971+
}
19681972
}
19691973
i = i + 4;
19701974
}
1975+
av_free(pkt);
19711976
}
19721977
}
19731978
}

0 commit comments

Comments
 (0)