int buf_size = avpkt->size;
PNMContext * const s = avctx->priv_data;
AVFrame * const p = data;
- int i, j, n, linesize, h, upgrade = 0, is_mono = 0;
+ int i, j, k, n, linesize, h, upgrade = 0, is_mono = 0;
unsigned char *ptr;
int components, sample_len, ret;
do_read:
ptr = p->data[0];
linesize = p->linesize[0];
- if (s->bytestream + n * avctx->height > s->bytestream_end)
+ if (n * avctx->height > s->bytestream_end - s->bytestream)
return AVERROR_INVALIDDATA;
if(s->type < 4 || (is_mono && s->type==7)){
for (i=0; i<avctx->height; i++) {
v = (*s->bytestream++)&1;
} else {
/* read a sequence of digits */
- do {
+ for (k = 0; k < 5 && c <= 9; k += 1) {
v = 10*v + c;
c = (*s->bytestream++) - '0';
- } while (c <= 9);
+ }
+ if (v > s->maxval) {
+ av_log(avctx, AV_LOG_ERROR, "value %d larger than maxval %d\n", v, s->maxval);
+ return AVERROR_INVALIDDATA;
+ }
}
if (sample_len == 16) {
((uint16_t*)ptr)[j] = (((1<<sample_len)-1)*v + (s->maxval>>1))/s->maxval;
linesize = p->linesize[0];
if (s->maxval >= 256)
n *= 2;
- if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end)
+ if (n * avctx->height * 3 / 2 > s->bytestream_end - s->bytestream)
return AVERROR_INVALIDDATA;
for (i = 0; i < avctx->height; i++) {
samplecpy(ptr, s->bytestream, n, s->maxval);
n = avctx->width * 2;
ptr = p->data[0];
linesize = p->linesize[0];
- if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end)
+ if (n * avctx->height * 3 / 2 > s->bytestream_end - s->bytestream)
return AVERROR_INVALIDDATA;
for (i = 0; i < avctx->height; i++) {
for (j = 0; j < n / 2; j++) {