Signed-off-by: Janne Grunau <janne-libav@jannau.net>
| ... | ... |
@@ -47,6 +47,7 @@ avs_decode_frame(AVCodecContext * avctx, |
| 47 | 47 |
void *data, int *data_size, AVPacket *avpkt) |
| 48 | 48 |
{
|
| 49 | 49 |
const uint8_t *buf = avpkt->data; |
| 50 |
+ const uint8_t *buf_end = avpkt->data + avpkt->size; |
|
| 50 | 51 |
int buf_size = avpkt->size; |
| 51 | 52 |
AvsContext *const avs = avctx->priv_data; |
| 52 | 53 |
AVFrame *picture = data; |
| ... | ... |
@@ -69,6 +70,8 @@ avs_decode_frame(AVCodecContext * avctx, |
| 69 | 69 |
out = avs->picture.data[0]; |
| 70 | 70 |
stride = avs->picture.linesize[0]; |
| 71 | 71 |
|
| 72 |
+ if (buf_end - buf < 4) |
|
| 73 |
+ return AVERROR_INVALIDDATA; |
|
| 72 | 74 |
sub_type = buf[0]; |
| 73 | 75 |
type = buf[1]; |
| 74 | 76 |
buf += 4; |
| ... | ... |
@@ -79,6 +82,8 @@ avs_decode_frame(AVCodecContext * avctx, |
| 79 | 79 |
|
| 80 | 80 |
first = AV_RL16(buf); |
| 81 | 81 |
last = first + AV_RL16(buf + 2); |
| 82 |
+ if (first >= 256 || last > 256 || buf_end - buf < 4 + 4 + 3 * (last - first)) |
|
| 83 |
+ return AVERROR_INVALIDDATA; |
|
| 82 | 84 |
buf += 4; |
| 83 | 85 |
for (i=first; i<last; i++, buf+=3) |
| 84 | 86 |
pal[i] = (buf[0] << 18) | (buf[1] << 10) | (buf[2] << 2); |
| ... | ... |
@@ -114,9 +119,13 @@ avs_decode_frame(AVCodecContext * avctx, |
| 114 | 114 |
return -1; |
| 115 | 115 |
} |
| 116 | 116 |
|
| 117 |
+ if (buf_end - buf < 256 * vect_w * vect_h) |
|
| 118 |
+ return AVERROR_INVALIDDATA; |
|
| 117 | 119 |
table = buf + (256 * vect_w * vect_h); |
| 118 | 120 |
if (sub_type != AVS_I_FRAME) {
|
| 119 | 121 |
int map_size = ((318 / vect_w + 7) / 8) * (198 / vect_h); |
| 122 |
+ if (buf_end - table < map_size) |
|
| 123 |
+ return AVERROR_INVALIDDATA; |
|
| 120 | 124 |
init_get_bits(&change_map, table, map_size * 8); |
| 121 | 125 |
table += map_size; |
| 122 | 126 |
} |
| ... | ... |
@@ -124,6 +133,8 @@ avs_decode_frame(AVCodecContext * avctx, |
| 124 | 124 |
for (y=0; y<198; y+=vect_h) {
|
| 125 | 125 |
for (x=0; x<318; x+=vect_w) {
|
| 126 | 126 |
if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) {
|
| 127 |
+ if (buf_end - table < 1) |
|
| 128 |
+ return AVERROR_INVALIDDATA; |
|
| 127 | 129 |
vect = &buf[*table++ * (vect_w * vect_h)]; |
| 128 | 130 |
for (j=0; j<vect_w; j++) {
|
| 129 | 131 |
out[(y + 0) * stride + x + j] = vect[(0 * vect_w) + j]; |