History

avformat/rtpdec: explicit timestamp wraparound handling

Change delta_timestamp to int32_t and add explicit cast to handle RTP timestamp wraparound correctly. This fixes implementation-defined behavior when computing negative timestamp differences due to 32-bit wraparound.

Clément Péron committed 1 year ago

Commit 52441bd1 parent 3f1f9db1 file · +4 −2Browse files

Unified · Split

libavformat/rtpdec.c+4−2
@@ -597,6 +597,7 @@ static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) { · 596 unmodified lines
597597 return AVERROR(ENOMEM);
598598
599599 rtcp_time = ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_US;
600+ /* Cast to int32_t to handle timestamp wraparound correctly */
600601 delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp);
601602 delta_time = av_rescale_q(delta_timestamp, s->st->time_base, AV_TIME_BASE_Q);
602603
@@ -624,10 +625,11 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam · 21 unmodified lines
624625
625626 if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE && s->ic->nb_streams > 1) {
626627 int64_t addend;
627− int delta_timestamp;
628+ int32_t delta_timestamp;
628629
629630 /* compute pts from timestamp with received ntp_time */
630− delta_timestamp = timestamp - s->last_rtcp_timestamp;
631+ /* Cast to int32_t to handle timestamp wraparound correctly */
632+ delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp);
631633 /* convert to the PTS timebase */
632634 addend = av_rescale(s->last_rtcp_ntp_time - s->first_rtcp_ntp_time,
633635 s->st->time_base.den,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t