]> granicus.if.org Git - libx264/commitdiff
Fix integer overflow detected by UBSan in --weightp analysis
authorAnton Mitrofanov <BugMaster@narod.ru>
Mon, 22 Apr 2019 18:41:43 +0000 (21:41 +0300)
committerAnton Mitrofanov <BugMaster@narod.ru>
Wed, 17 Jul 2019 17:15:34 +0000 (20:15 +0300)
Bug report by Xuezhi Yan.

encoder/slicetype.c

index 18885e798d2bede04b281cfc41a0355e1974b224..a520f5864db6dd65870aaf5f6207f9b59121a9bc 100644 (file)
@@ -405,8 +405,7 @@ void x264_weights_analyse( x264_t *h, x264_frame_t *fenc, x264_frame_t *ref, int
                  * because scale has a much wider range than offset (because of denom), so
                  * it should almost never need to be clamped. */
                 cur_offset = x264_clip3( cur_offset, -128, 127 );
-                cur_scale = (1 << mindenom) * (fenc_mean[plane] - cur_offset) / ref_mean[plane] + 0.5f;
-                cur_scale = x264_clip3( cur_scale, 0, 127 );
+                cur_scale = x264_clip3f( (1 << mindenom) * (fenc_mean[plane] - cur_offset) / ref_mean[plane] + 0.5f, 0, 127 );
             }
             int start_offset = x264_clip3( cur_offset - offset_dist, -128, 127 );
             int end_offset   = x264_clip3( cur_offset + offset_dist, -128, 127 );