if (next == END_NOT_FOUND)
pnmpc->ascii_scan = sync - pnmctx.bytestream + skip;
} else {
- next = pnmctx.bytestream - pnmctx.bytestream_start + skip
- + av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);
+ int ret = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);
+ next = pnmctx.bytestream - pnmctx.bytestream_start + skip;
+ if (ret >= 0 && next + (uint64_t)ret <= INT_MAX)
+ next += ret;
}
if (next != END_NOT_FOUND && pnmctx.bytestream_start != buf + skip)
next -= pc->index;