diff options
Diffstat (limited to 'libavcodec/yop.c')
-rw-r--r-- | libavcodec/yop.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/libavcodec/yop.c b/libavcodec/yop.c index 69700bd266..c47f5ec14f 100644 --- a/libavcodec/yop.c +++ b/libavcodec/yop.c @@ -5,20 +5,20 @@ * derived from the code by * Copyright (C) 2009 Thomas P. Higdon <thomas.p.higdon@gmail.com> * - * 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 */ @@ -89,8 +89,14 @@ static av_cold int yop_decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } + if (!avctx->extradata) { + av_log(avctx, AV_LOG_ERROR, "extradata missing\n"); + return AVERROR_INVALIDDATA; + } + avctx->pix_fmt = AV_PIX_FMT_PAL8; + avcodec_get_frame_defaults(&s->frame); s->num_pal_colors = avctx->extradata[0]; s->first_color[0] = avctx->extradata[1]; s->first_color[1] = avctx->extradata[2]; @@ -98,7 +104,7 @@ static av_cold int yop_decode_init(AVCodecContext *avctx) if (s->num_pal_colors + s->first_color[0] > 256 || s->num_pal_colors + s->first_color[1] > 256) { av_log(avctx, AV_LOG_ERROR, - "YOP: palette parameters invalid, header probably corrupt\n"); + "Palette parameters invalid, header probably corrupt\n"); return AVERROR_INVALIDDATA; } @@ -141,8 +147,7 @@ static int yop_copy_previous_block(YopDecContext *s, int copy_tag) bufptr = s->dstptr + motion_vector[copy_tag][0] + s->frame.linesize[0] * motion_vector[copy_tag][1]; if (bufptr < s->dstbuf) { - av_log(s->avctx, AV_LOG_ERROR, - "YOP: cannot decode, file probably corrupt\n"); + av_log(s->avctx, AV_LOG_ERROR, "File probably corrupt\n"); return AVERROR_INVALIDDATA; } @@ -183,6 +188,11 @@ static int yop_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); + if (avpkt->size < 4 + 3*s->num_pal_colors) { + av_log(avctx, AV_LOG_ERROR, "packet of size %d too small\n", avpkt->size); + return AVERROR_INVALIDDATA; + } + ret = ff_get_buffer(avctx, &s->frame); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); @@ -195,13 +205,20 @@ static int yop_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, s->low_nibble = NULL; is_odd_frame = avpkt->data[0]; + if(is_odd_frame>1){ + av_log(avctx, AV_LOG_ERROR, "frame is too odd %d\n", is_odd_frame); + return AVERROR_INVALIDDATA; + } firstcolor = s->first_color[is_odd_frame]; palette = (uint32_t *)s->frame.data[1]; - for (i = 0; i < s->num_pal_colors; i++, s->srcptr += 3) + for (i = 0; i < s->num_pal_colors; i++, s->srcptr += 3) { palette[i + firstcolor] = (s->srcptr[0] << 18) | (s->srcptr[1] << 10) | (s->srcptr[2] << 2); + palette[i + firstcolor] |= 0xFFU << 24 | + (palette[i + firstcolor] >> 6) & 0x30303; + } s->frame.palette_has_changed = 1; @@ -243,5 +260,4 @@ AVCodec ff_yop_decoder = { .close = yop_decode_close, .decode = yop_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("Psygnosis YOP Video"), - .capabilities = CODEC_CAP_DR1, }; |