]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/tta.c
alac: fix check for valid max_samples_per_frame
[ffmpeg] / libavcodec / tta.c
index acaeaaa94846c3b26e7a1392930d72f90586776c..0650086dcd992b1405c42fbf342b36700075f625 100644 (file)
@@ -61,7 +61,8 @@ typedef struct TTAContext {
     GetBitContext gb;
     const AVCRC *crc_table;
 
-    int format, channels, bps, data_length;
+    int format, channels, bps;
+    unsigned data_length;
     int frame_length, last_frame_length, total_frames;
 
     int32_t *decode_buffer;
@@ -253,7 +254,7 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
         }
 
         // prevent overflow
-        if (avctx->sample_rate > 0x7FFFFF) {
+        if (avctx->sample_rate > 0x7FFFFFu) {
             av_log(avctx, AV_LOG_ERROR, "sample_rate too large\n");
             return AVERROR(EINVAL);
         }
@@ -270,7 +271,8 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
             s->data_length, s->frame_length, s->last_frame_length, s->total_frames);
 
         // FIXME: seek table
-        if (get_bits_left(&s->gb) < 32 * s->total_frames + 32)
+        if (avctx->extradata_size <= 26 || s->total_frames > INT_MAX / 4 ||
+            avctx->extradata_size - 26 < s->total_frames * 4)
             av_log(avctx, AV_LOG_WARNING, "Seek table missing or too small\n");
         else if (avctx->err_recognition & AV_EF_CRCCHECK) {
             if (tta_check_crc(s, avctx->extradata + 22, s->total_frames * 4))
@@ -414,7 +416,7 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
         if (cur_chan < (s->channels-1))
             cur_chan++;
         else {
-            // decorrelate in case of stereo integer
+            // decorrelate in case of multiple channels
             if (s->channels > 1) {
                 int32_t *r = p - 1;
                 for (*p += *r / 2; r > p - s->channels; r--)