]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pcm.c
avformat/apngdec: Make sure that extradata is zero-padded
[ffmpeg] / libavcodec / pcm.c
index ffcbccc77db58a7082856ad95dcaa3b04a91d824..4ce0b9487bb38803dca330d3128de973968ae23a 100644 (file)
@@ -264,6 +264,9 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
         break;
     case AV_CODEC_ID_PCM_F16LE:
     case AV_CODEC_ID_PCM_F24LE:
+        if (avctx->bits_per_coded_sample < 1 || avctx->bits_per_coded_sample > 24)
+            return AVERROR_INVALIDDATA;
+
         s->scale = 1. / (1 << (avctx->bits_per_coded_sample - 1));
         s->fdsp = avpriv_float_dsp_alloc(0);
         if (!s->fdsp)
@@ -300,23 +303,23 @@ static av_cold int pcm_decode_close(AVCodecContext *avctx)
  * @param shift  Bitshift (bits)
  * @param offset Sample value offset
  */
-#define DECODE(size, endian, src, dst, n, shift, offset)                \
-    for (; n > 0; n--) {                                                \
-        uint ## size ## _t v = bytestream_get_ ## endian(&src);         \
-        AV_WN ## size ## A(dst, (v - offset) << shift);                 \
-        dst += size / 8;                                                \
+#define DECODE(size, endian, src, dst, n, shift, offset)                       \
+    for (; n > 0; n--) {                                                       \
+        uint ## size ## _t v = bytestream_get_ ## endian(&src);                \
+        AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift);    \
+        dst += size / 8;                                                       \
     }
 
-#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)         \
-    n /= avctx->channels;                                               \
-    for (c = 0; c < avctx->channels; c++) {                             \
-        int i;                                                          \
-        dst = frame->extended_data[c];                                \
-        for (i = n; i > 0; i--) {                                       \
-            uint ## size ## _t v = bytestream_get_ ## endian(&src);     \
-            AV_WN ## size ## A(dst, (v - offset) << shift);             \
-            dst += size / 8;                                            \
-        }                                                               \
+#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)                \
+    n /= avctx->channels;                                                      \
+    for (c = 0; c < avctx->channels; c++) {                                    \
+        int i;                                                                 \
+        dst = frame->extended_data[c];                                         \
+        for (i = n; i > 0; i--) {                                              \
+            uint ## size ## _t v = bytestream_get_ ## endian(&src);            \
+            AV_WN ## size ## A(dst, (uint ## size ##_t)(v - offset) << shift); \
+            dst += size / 8;                                                   \
+        }                                                                      \
     }
 
 static int pcm_decode_frame(AVCodecContext *avctx, void *data,