summaryrefslogtreecommitdiff
path: root/libavcodec/8bps.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-07-24 11:41:39 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-07-24 11:45:54 +0200
commitda0f67b177adaa3f792038bff174d015da1179a4 (patch)
tree61ae8fb8084737f7a2925d7b78ff4330291e1e33 /libavcodec/8bps.c
parent82654172ced59236744bb7aceba822462f6b5750 (diff)
parentbd7b4da0f4627bb6c4a7c2575da83fe6b261a21c (diff)
downloadffmpeg-da0f67b177adaa3f792038bff174d015da1179a4.tar.gz
Merge commit 'bd7b4da0f4627bb6c4a7c2575da83fe6b261a21c'
* commit 'bd7b4da0f4627bb6c4a7c2575da83fe6b261a21c': 8bps: Bound-check the input buffer Conflicts: libavcodec/8bps.c See: 66ff90f4a3d81c25feaa672dc8cc9cc88017753d Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/8bps.c')
-rw-r--r--libavcodec/8bps.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/libavcodec/8bps.c b/libavcodec/8bps.c
index a910551410..2c03e8b4a3 100644
--- a/libavcodec/8bps.c
+++ b/libavcodec/8bps.c
@@ -64,7 +64,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
unsigned char *pixptr, *pixptr_end;
unsigned int height = avctx->height; // Real image height
unsigned int dlen, p, row;
- const unsigned char *lp, *dp;
+ const unsigned char *lp, *dp, *ep;
unsigned char count;
unsigned int planes = c->planes;
unsigned char *planemap = c->planemap;
@@ -73,6 +73,8 @@ static int decode_frame(AVCodecContext *avctx, void *data,
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
+ ep = encoded + buf_size;
+
/* Set data pointer after line lengths */
dp = encoded + planes * (height << 1);
@@ -84,19 +86,19 @@ static int decode_frame(AVCodecContext *avctx, void *data,
for (row = 0; row < height; row++) {
pixptr = frame->data[0] + row * frame->linesize[0] + planemap[p];
pixptr_end = pixptr + frame->linesize[0];
- if(lp - encoded + row*2 + 1 >= buf_size)
- return -1;
+ if (ep - lp < row * 2 + 2)
+ return AVERROR_INVALIDDATA;
dlen = av_be2ne16(*(const unsigned short *)(lp + row * 2));
/* Decode a row of this plane */
while (dlen > 0) {
- if (dp + 1 >= buf + buf_size)
+ if (ep - dp <= 1)
return AVERROR_INVALIDDATA;
if ((count = *dp++) <= 127) {
count++;
dlen -= count + 1;
if (pixptr + count * planes > pixptr_end)
break;
- if (dp + count > buf + buf_size)
+ if (ep - dp < count)
return AVERROR_INVALIDDATA;
while (count--) {
*pixptr = *dp++;