int next = END_NOT_FOUND;
int skip = 0;
- for (; pc->overread > 0; pc->overread--) {
- pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
+ if (pc->overread > 0) {
+ memmove(pc->buffer + pc->index, pc->buffer + pc->overread_index, pc->overread);
+ pc->index += pc->overread;
+ pc->overread_index += pc->overread;
+ pc->overread = 0;
}
if (pnmpc->remaining_bytes) {
if (pnmctx.bytestream < pnmctx.bytestream_end) {
if (pc->index) {
pc->index = 0;
+ pnmpc->ascii_scan = 0;
} else {
unsigned step = FFMAX(1, pnmctx.bytestream - pnmctx.bytestream_start);
sync = bs;
c = *bs++;
if (c == '#') {
- while (c != '\n' && bs < end)
- c = *bs++;
+ uint8_t *match = memchr(bs, '\n', end-bs);
+ if (match)
+ bs = match + 1;
+ else
+ break;
} else if (c == 'P') {
next = bs - pnmctx.bytestream_start + skip - 1;
pnmpc->ascii_scan = 0;
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;
return next;
}
-AVCodecParser ff_pnm_parser = {
+const AVCodecParser ff_pnm_parser = {
.codec_ids = { AV_CODEC_ID_PGM, AV_CODEC_ID_PGMYUV, AV_CODEC_ID_PPM,
AV_CODEC_ID_PBM, AV_CODEC_ID_PAM },
.priv_data_size = sizeof(PNMParseContext),