]> git.videolan.org Git - x264.git/commitdiff
Fix integer overflow in chroma SSD check
authorJason Garrett-Glaser <darkshikari@gmail.com>
Mon, 22 Feb 2010 19:21:51 +0000 (11:21 -0800)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Mon, 22 Feb 2010 19:46:27 +0000 (11:46 -0800)
Could cause bad skips at very high quantizers on extreme inputs.

encoder/rdo.c

index 3ed4a478caeda5a6d66e222e8fd0d4b3ca016746..e15f47d50075afcb22872c33ac95dc2c85531bae 100644 (file)
@@ -131,7 +131,7 @@ static inline int ssd_plane( x264_t *h, int size, int p, int x, int y )
 static inline int ssd_mb( x264_t *h )
 {
     int chromassd = ssd_plane(h, PIXEL_8x8, 1, 0, 0) + ssd_plane(h, PIXEL_8x8, 2, 0, 0);
-    chromassd = (chromassd * h->mb.i_chroma_lambda2_offset + 128) >> 8;
+    chromassd = ((uint64_t)chromassd * h->mb.i_chroma_lambda2_offset + 128) >> 8;
     return ssd_plane(h, PIXEL_16x16, 0, 0, 0) + chromassd;
 }
 
@@ -223,7 +223,7 @@ uint64_t x264_rd_cost_part( x264_t *h, int i_lambda2, int i4, int i_pixel )
 
     chromassd = ssd_plane( h, i_pixel+3, 1, (i8&1)*4, (i8>>1)*4 )
               + ssd_plane( h, i_pixel+3, 2, (i8&1)*4, (i8>>1)*4 );
-    chromassd = (chromassd * h->mb.i_chroma_lambda2_offset + 128) >> 8;
+    chromassd = ((uint64_t)chromassd * h->mb.i_chroma_lambda2_offset + 128) >> 8;
     i_ssd = ssd_plane( h, i_pixel,   0, (i8&1)*8, (i8>>1)*8 ) + chromassd;
 
     if( h->param.b_cabac )