diff options
Diffstat (limited to 'libavcodec/dfa.c')
-rw-r--r-- | libavcodec/dfa.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/libavcodec/dfa.c b/libavcodec/dfa.c index 119be7066c..b324c6e5ba 100644 --- a/libavcodec/dfa.c +++ b/libavcodec/dfa.c @@ -3,23 +3,24 @@ * Copyright (c) 2011 Konstantin Shishkov * based on work by Vladimir "VAG" Gneushev * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avassert.h" #include "avcodec.h" #include "bytestream.h" #include "internal.h" @@ -37,12 +38,13 @@ typedef struct DfaContext { static av_cold int dfa_decode_init(AVCodecContext *avctx) { DfaContext *s = avctx->priv_data; - int ret; avctx->pix_fmt = AV_PIX_FMT_PAL8; - if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) - return ret; + if (!avctx->width || !avctx->height) + return AVERROR_INVALIDDATA; + + av_assert0(av_image_check_size(avctx->width, avctx->height, 0, avctx) >= 0); s->frame_buf = av_mallocz(avctx->width * avctx->height); if (!s->frame_buf) @@ -70,6 +72,8 @@ static int decode_tsw1(GetByteContext *gb, uint8_t *frame, int width, int height segments = bytestream2_get_le32(gb); offset = bytestream2_get_le32(gb); + if (segments == 0 && offset == frame_end - frame) + return 0; // skip frame if (frame_end - frame <= offset) return AVERROR_INVALIDDATA; frame += offset; @@ -252,6 +256,8 @@ static int decode_wdlt(GetByteContext *gb, uint8_t *frame, int width, int height y += skip_lines; segments = bytestream2_get_le16(gb); } + if (frame_end <= frame) + return -1; if (segments & 0x8000) { frame[width - 1] = segments & 0xFF; segments = bytestream2_get_le16(gb); @@ -338,7 +344,7 @@ static int dfa_decode_frame(AVCodecContext *avctx, pal_elems = FFMIN(chunk_size / 3, 256); for (i = 0; i < pal_elems; i++) { s->pal[i] = bytestream2_get_be24(&gb) << 2; - s->pal[i] |= (s->pal[i] >> 6) & 0x333; + s->pal[i] |= 0xFFU << 24 | (s->pal[i] >> 6) & 0x30303; } s->pic.palette_has_changed = 1; } else if (chunk_type <= 9) { |