Merge commit 'cdbaa436042ba59c3b2bd7e9652e9a14136fd604'
authorDerek Buitenhuis <derek.buitenhuis@gmail.com>
Tue, 16 Feb 2016 18:57:41 +0000 (18:57 +0000)
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>
Tue, 16 Feb 2016 19:01:05 +0000 (19:01 +0000)
* commit 'cdbaa436042ba59c3b2bd7e9652e9a14136fd604':
  mpeg12dec: Always close reader on error

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
1  2 
libavcodec/mpeg12dec.c

@@@ -165,9 -166,13 +166,10 @@@ static inline int mpeg1_decode_block_in
              GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0],
                         TEX_VLC_BITS, 2, 0);
  
 -            if (level == 127) {
 -                break;
 -            } else if (level != 0) {
 +            if (level != 0) {
                  i += run;
-                 check_scantable_index(s, i);
+                 if (i > MAX_INDEX)
+                     break;
                  j = scantable[i];
                  level = (level * qscale * quant_matrix[j]) >> 4;
                  level = (level - 1) | 1;
                  SKIP_BITS(re, &s->gb, 8);
                  if (level == -128) {
                      level = SHOW_UBITS(re, &s->gb, 8) - 256;
 -                    LAST_SKIP_BITS(re, &s->gb, 8);
 +                    SKIP_BITS(re, &s->gb, 8);
                  } else if (level == 0) {
                      level = SHOW_UBITS(re, &s->gb, 8);
 -                    LAST_SKIP_BITS(re, &s->gb, 8);
 +                    SKIP_BITS(re, &s->gb, 8);
                  }
                  i += run;
-                 check_scantable_index(s, i);
+                 if (i > MAX_INDEX)
+                     break;
                  j = scantable[i];
                  if (level < 0) {
                      level = -level;
              }
  
              block[j] = level;
 +            if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
 +               break;
 +
 +            UPDATE_CACHE(re, &s->gb);
          }
 +end:
 +        LAST_SKIP_BITS(re, &s->gb, 2);
          CLOSE_READER(re, &s->gb);
      }
+     check_scantable_index(s, i);
      s->block_last_index[n] = i;
      return 0;
  }