]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pngdec.c
wmavoice: move overflow handling to common code.
[ffmpeg] / libavcodec / pngdec.c
index 83eeb8d322aef97f81af0080594a4c80191bce2d..2f8d266c2779ef3734af2b4f35e44c9a763fe878 100644 (file)
@@ -45,9 +45,6 @@ typedef struct PNGDecContext {
     ThreadFrame last_picture;
     ThreadFrame picture;
 
-    uint8_t* extra_data;
-    int extra_data_size;
-
     int state;
     int width, height;
     int cur_w, cur_h;
@@ -925,7 +922,8 @@ static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s,
         return AVERROR_INVALIDDATA;
     }
 
-    if (sequence_number == 0 && dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
+    if ((sequence_number == 0 || !s->previous_picture.f->data[0]) &&
+        dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
         // No previous frame to revert to for the first frame
         // Spec says to just treat it as a APNG_DISPOSE_OP_BACKGROUND
         dispose_op = APNG_DISPOSE_OP_BACKGROUND;
@@ -1364,28 +1362,14 @@ static int decode_frame_apng(AVCodecContext *avctx,
     p = s->picture.f;
 
     if (!(s->state & PNG_IHDR)) {
-        int side_data_size = 0;
-        uint8_t *side_data = NULL;
-        if (avpkt)
-            side_data = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &side_data_size);
-
-        if (side_data_size) {
-            av_freep(&s->extra_data);
-            s->extra_data = av_mallocz(side_data_size + AV_INPUT_BUFFER_PADDING_SIZE);
-            if (!s->extra_data)
-                return AVERROR(ENOMEM);
-            s->extra_data_size = side_data_size;
-            memcpy(s->extra_data, side_data, s->extra_data_size);
-        }
-
-        if (!s->extra_data_size)
+        if (!avctx->extradata_size)
             return AVERROR_INVALIDDATA;
 
         /* only init fields, there is no zlib use in extradata */
         s->zstream.zalloc = ff_png_zalloc;
         s->zstream.zfree  = ff_png_zfree;
 
-        bytestream2_init(&s->gb, s->extra_data, s->extra_data_size);
+        bytestream2_init(&s->gb, avctx->extradata, avctx->extradata_size);
         if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0)
             goto end;
     }
@@ -1511,8 +1495,6 @@ static av_cold int png_dec_end(AVCodecContext *avctx)
     s->last_row_size = 0;
     av_freep(&s->tmp_row);
     s->tmp_row_size = 0;
-    av_freep(&s->extra_data);
-    s->extra_data_size = 0;
 
     return 0;
 }