<div dir="ltr">Yes, confirm that this fix works. Thanks for making this fix.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 22, 2019 at 3:21 PM BugMaster <<a href="mailto:BugMaster@narod.ru">BugMaster@narod.ru</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, 18 Apr 2019 16:43:05 -0700, Xuezhi Yan wrote:<br>
> Hi, while running x264 under Clang's UndefinedBehaviorSanitizer,<br>
> I'm hitting integer overflow in the following line:<br>
<br>
<br>
<br>
> <a href="https://code.videolan.org/videolan/x264/blob/master/encoder/slicetype.c#L408" rel="noreferrer" target="_blank">https://code.videolan.org/videolan/x264/blob/master/encoder/slicetype.c#L408</a><br>
<br>
<br>
<br>
> where "ref_mean[plane]" is 0.000003 because the reference frame's<br>
> "i_pixel_sum[plane]" is 0 ("ref_mean[plane]" is not zero because<br>
> zero_bias is added). With the following clamping using float I am able to fix the problem locally:<br>
<br>
<br>
> 408,409c408,409 encoder/slicetype.c<br>
> <    cur_scale = (1 << mindenom) * (fenc_mean[plane] - cur_offset) / ref_mean[plane] + 0.5f;<br>
> <    cur_scale = x264_clip3( cur_scale, 0, 127 );<br>
> ---<br>
>>    float temp = (1 << mindenom) * (fenc_mean[plane] - cur_offset) / ref_mean[plane] + 0.5f;<br>
>>    cur_scale = temp > 127.0f ? 127 : (temp < 0.0f ? 0 : x264_clip3( temp, 0, 127 ));<br>
<br>
<br>
> If this looks good, can someone help me merge it? Otherwise is there a more appropriate fix?<br>
<br>
Hi.<br>
<br>
Thanks for bug report. I have attached patch with more correct/clean fix.<br>
Check that it works for you._______________________________________________<br>
x264-devel mailing list<br>
<a href="mailto:x264-devel@videolan.org" target="_blank">x264-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x264-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x264-devel</a><br>
</blockquote></div>