summaryrefslogtreecommitdiff
path: root/libavcodec/yop.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/yop.c')
-rw-r--r--libavcodec/yop.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/libavcodec/yop.c b/libavcodec/yop.c
index 0b9cdfebe2..337fb88365 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
*/
@@ -85,12 +85,17 @@ static av_cold int yop_decode_init(AVCodecContext *avctx)
if (avctx->width & 1 || avctx->height & 1 ||
av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) {
- av_log(avctx, AV_LOG_ERROR, "YOP has invalid dimensions\n");
return -1;
}
+ 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 +103,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 +146,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 +187,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 +204,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 +259,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,
};