]> granicus.if.org Git - libx264/commitdiff
Fix undefined behavior: index out of bounds (one more)
authorAnton Mitrofanov <BugMaster@narod.ru>
Sat, 25 Apr 2020 23:56:25 +0000 (02:56 +0300)
committerAnton Mitrofanov <BugMaster@narod.ru>
Wed, 10 Jun 2020 15:07:03 +0000 (18:07 +0300)
last_non_b_pict_type is initialized to -1.
Bug report by Vitaly Buka.

encoder/ratecontrol.c

index 32b5e1e36ef073d7b855f8f97255ebd2553798fb..e6d292bc1dc905811ebc322c478d3da59accd942 100644 (file)
@@ -2030,8 +2030,6 @@ static double get_diff_limited_q(x264_t *h, ratecontrol_entry_t *rce, double q,
     x264_zone_t *zone = get_zone( h, frame_num );
 
     // force I/B quants as a function of P quants
-    const double last_p_q    = rcc->last_qscale_for[SLICE_TYPE_P];
-    const double last_non_b_q= rcc->last_qscale_for[rcc->last_non_b_pict_type];
     if( pict_type == SLICE_TYPE_I )
     {
         double iq = q;
@@ -2050,7 +2048,7 @@ static double get_diff_limited_q(x264_t *h, ratecontrol_entry_t *rce, double q,
     else if( pict_type == SLICE_TYPE_B )
     {
         if( h->param.rc.f_pb_factor > 0 )
-            q = last_non_b_q;
+            q = rcc->last_qscale_for[rcc->last_non_b_pict_type];
         if( !rce->kept_as_ref )
             q *= fabs( h->param.rc.f_pb_factor );
     }
@@ -2058,7 +2056,7 @@ static double get_diff_limited_q(x264_t *h, ratecontrol_entry_t *rce, double q,
              && rcc->last_non_b_pict_type == SLICE_TYPE_P
              && rce->tex_bits == 0 )
     {
-        q = last_p_q;
+        q = rcc->last_qscale_for[SLICE_TYPE_P];
     }
 
     /* last qscale / qdiff stuff */