[vlc-commits] rtp sout: fix integer overflow

Pierre Ynard git at videolan.org
Sun Feb 5 03:50:42 CET 2012


vlc/vlc-2.0 | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Sun Feb  5 03:29:47 2012 +0100| [d875f53b162d9cbc488a18814999b2e70627ca2f] | committer: Pierre Ynard

rtp sout: fix integer overflow

This became likely to happen using VoD. Thanks to Denis Charmet for
pointing out this issue.
(cherry picked from commit 7ed3e0e4fa7b2e1d33f78eebab2b1b4fa9201049)

Signed-off-by: Pierre Ynard <linkfanel at yahoo.fr>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=d875f53b162d9cbc488a18814999b2e70627ca2f
---

 modules/stream_out/rtp.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c
index d2b6500..5900172 100644
--- a/modules/stream_out/rtp.c
+++ b/modules/stream_out/rtp.c
@@ -946,9 +946,14 @@ rtp_set_ptime (sout_stream_id_t *id, unsigned ptime_ms, size_t bytes)
 
 uint32_t rtp_compute_ts( unsigned i_clock_rate, int64_t i_pts )
 {
-    /* NOTE: this plays nice with offsets because the calculations are
-     * linear. */
-    return i_pts * (int64_t)i_clock_rate / CLOCK_FREQ;
+    /* This is an overflow-proof way of doing:
+     * return i_pts * (int64_t)i_clock_rate / CLOCK_FREQ;
+     *
+     * NOTE: this plays nice with offsets because the (equivalent)
+     * calculations are linear. */
+    lldiv_t q = lldiv(i_pts, CLOCK_FREQ);
+    return q.quot * (int64_t)i_clock_rate
+          + q.rem * (int64_t)i_clock_rate / CLOCK_FREQ;
 }
 
 /** Add an ES as a new RTP stream */



More information about the vlc-commits mailing list