]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/alac.c
lavc: support extracting audio service type from side data
[ffmpeg] / libavcodec / alac.c
index 41d1f772e8ada4acd62a19b72943b49693ae49d0..5272f8416c68e5dd22b74203f3e60e59f93f611a 100644 (file)
@@ -45,6 +45,8 @@
  * 32bit  samplerate
  */
 
+#include <inttypes.h>
+
 #include "libavutil/channel_layout.h"
 #include "avcodec.h"
 #include "get_bits.h"
@@ -276,7 +278,7 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index,
     else
         output_samples = alac->max_samples_per_frame;
     if (!output_samples || output_samples > alac->max_samples_per_frame) {
-        av_log(avctx, AV_LOG_ERROR, "invalid samples per frame: %d\n",
+        av_log(avctx, AV_LOG_ERROR, "invalid samples per frame: %"PRIu32"\n",
                output_samples);
         return AVERROR_INVALIDDATA;
     }
@@ -288,7 +290,7 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index,
             return ret;
         }
     } else if (output_samples != alac->nb_samples) {
-        av_log(avctx, AV_LOG_ERROR, "sample count mismatch: %u != %d\n",
+        av_log(avctx, AV_LOG_ERROR, "sample count mismatch: %"PRIu32" != %d\n",
                output_samples, alac->nb_samples);
         return AVERROR_INVALIDDATA;
     }
@@ -314,6 +316,9 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index,
             rice_history_mult[ch] = get_bits(&alac->gb, 3);
             lpc_order[ch]         = get_bits(&alac->gb, 5);
 
+            if (lpc_order[ch] >= alac->max_samples_per_frame)
+                return AVERROR_INVALIDDATA;
+
             /* read the predictor table */
             for (i = lpc_order[ch] - 1; i >= 0; i--)
                 lpc_coefs[ch][i] = get_sbits(&alac->gb, 16);
@@ -497,7 +502,8 @@ static int alac_set_info(ALACContext *alac)
     alac->max_samples_per_frame = bytestream2_get_be32u(&gb);
     if (!alac->max_samples_per_frame ||
         alac->max_samples_per_frame > INT_MAX / sizeof(int32_t)) {
-        av_log(alac->avctx, AV_LOG_ERROR, "max samples per frame invalid: %u\n",
+        av_log(alac->avctx, AV_LOG_ERROR,
+               "max samples per frame invalid: %"PRIu32"\n",
                alac->max_samples_per_frame);
         return AVERROR_INVALIDDATA;
     }
@@ -568,6 +574,7 @@ static av_cold int alac_decode_init(AVCodecContext * avctx)
 
 AVCodec ff_alac_decoder = {
     .name           = "alac",
+    .long_name      = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_ALAC,
     .priv_data_size = sizeof(ALACContext),
@@ -575,5 +582,4 @@ AVCodec ff_alac_decoder = {
     .close          = alac_decode_close,
     .decode         = alac_decode_frame,
     .capabilities   = CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
 };