[vlc-devel] [PATCH] demux/asf: fix 17579: prevent signed integer overflow
Rémi Denis-Courmont
remi at remlab.net
Tue Nov 1 14:00:44 CET 2016
Le tiistaina 1. marraskuuta 2016, 2.04.06 EET Filip Roséen a écrit :
> The previous implementation could overflow the mtime_t when
> multiplying p_sys->p_fp->i_preroll by a thousand when converting from
> the asf time unit (milliseconds) to VLCs (microseconds).
>
> Given that you can always divide a value without running into issues
> in terms of under/overflow, these changes prevent any overflow error
> while still preserving the same logic.
>
> In short the implementation takes advantage of the below two
> conditions being equivalent:
>
> 1: A > ( ( B * C ) + D )
> 2: ( ( A - D ) / C ) > B
That´s true with reals, not with integers. For instance,
with A=2, B=0, C=2, D=1:
(1) <=> 2 > ((0 * 2) + 1 <=> 2 > 1 <=> true
(2) <=> ((2 - 1) / 2) > 0 <=> (1 / 2) > 0 <=> 0 > 0 <=> false
(I don´t know if it affects the correctness of the diff.)
--
Rémi Denis-Courmont
http://www.remlab.net/
More information about the vlc-devel
mailing list