diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-04-21 16:00:51 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-04-21 16:00:51 +0200 |
commit | 8401ed651b2c6b089ebb6d5afbf05e662dfbf87e (patch) | |
tree | 322928cb3f55ac505845e80fcc15f82be4d37695 | |
parent | fcaf78f5f94130471dcbd9fa63e8363ce2fdefe0 (diff) | |
parent | ea1806ce650f0502dd25939c335b9216fa4a955f (diff) | |
download | ffmpeg-8401ed651b2c6b089ebb6d5afbf05e662dfbf87e.tar.gz |
Merge commit 'ea1806ce650f0502dd25939c335b9216fa4a955f' into release/1.1
* commit 'ea1806ce650f0502dd25939c335b9216fa4a955f':
sgidec: fix buffer size check in expand_rle_row()
Conflicts:
libavcodec/sgidec.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavcodec/sgidec.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/libavcodec/sgidec.c b/libavcodec/sgidec.c index 555b5044af..f83edf1144 100644 --- a/libavcodec/sgidec.c +++ b/libavcodec/sgidec.c @@ -28,6 +28,7 @@ typedef struct SgiState { AVFrame picture; + AVCodecContext *avctx; unsigned int width; unsigned int height; unsigned int depth; @@ -40,15 +41,16 @@ typedef struct SgiState { * Expand an RLE row into a channel. * @param s the current image state * @param out_buf Points to one line after the output buffer. - * @param out_end end of line in output buffer + * @param len length of out_buf in bytes * @param pixelstride pixel stride of input buffer * @return size of output in bytes, -1 if buffer overflows */ static int expand_rle_row(SgiState *s, uint8_t *out_buf, - uint8_t *out_end, int pixelstride) + int len, int pixelstride) { unsigned char pixel, count; unsigned char *orig = out_buf; + uint8_t *out_end = out_buf + len; while (out_buf < out_end) { if (bytestream2_get_bytes_left(&s->g) < 1) @@ -59,7 +61,10 @@ static int expand_rle_row(SgiState *s, uint8_t *out_buf, } /* Check for buffer overflow. */ - if(out_buf + pixelstride * (count-1) >= out_end) return -1; + if (out_end - out_buf <= pixelstride * (count - 1)) { + av_log(s->avctx, AV_LOG_ERROR, "Invalid pixel count.\n"); + return AVERROR_INVALIDDATA; + } if (pixel & 0x80) { while (count--) { @@ -103,7 +108,7 @@ static int read_rle_sgi(uint8_t *out_buf, SgiState *s) dest_row -= s->linesize; start_offset = bytestream2_get_be32(&g_table); bytestream2_seek(&s->g, start_offset, SEEK_SET); - if (expand_rle_row(s, dest_row + z, dest_row + s->width*s->depth, + if (expand_rle_row(s, dest_row + z, s->width*s->depth, s->depth) != s->width) { return AVERROR_INVALIDDATA; } @@ -260,6 +265,15 @@ static av_cold int sgi_end(AVCodecContext *avctx) return 0; } +static av_cold int sgi_decode_init(AVCodecContext *avctx) +{ + SgiState *s = avctx->priv_data; + + s->avctx = avctx; + + return 0; +} + AVCodec ff_sgi_decoder = { .name = "sgi", .type = AVMEDIA_TYPE_VIDEO, @@ -269,5 +283,6 @@ AVCodec ff_sgi_decoder = { .close = sgi_end, .decode = decode_frame, .long_name = NULL_IF_CONFIG_SMALL("SGI image"), + .init = sgi_decode_init, .capabilities = CODEC_CAP_DR1, }; |