| 36 | } WebPParseContext; |
| 37 | |
| 38 | static int webp_parse(AVCodecParserContext *s, AVCodecContext *avctx, |
| 39 | const uint8_t **poutbuf, int *poutbuf_size, |
| 40 | const uint8_t *buf, int buf_size) |
| 41 | { |
| 42 | WebPParseContext *ctx = s->priv_data; |
| 43 | uint64_t state = ctx->pc.state64; |
| 44 | int next = END_NOT_FOUND; |
| 45 | int i = 0; |
| 46 | |
| 47 | *poutbuf = NULL; |
| 48 | *poutbuf_size = 0; |
| 49 | |
| 50 | restart: |
| 51 | if (ctx->pc.frame_start_found <= 8) { |
| 52 | for (; i < buf_size; i++) { |
| 53 | state = (state << 8) | buf[i]; |
| 54 | if (ctx->pc.frame_start_found == 0) { |
| 55 | if ((state >> 32) == MKBETAG('R', 'I', 'F', 'F')) { |
| 56 | ctx->fsize = av_bswap32(state); |
| 57 | if (ctx->fsize > 15 && ctx->fsize <= UINT32_MAX - 10) { |
| 58 | ctx->pc.frame_start_found = 1; |
| 59 | ctx->fsize += 8; |
| 60 | } |
| 61 | } |
| 62 | } else if (ctx->pc.frame_start_found == 8) { |
| 63 | if ((state >> 32) != MKBETAG('W', 'E', 'B', 'P')) { |
| 64 | ctx->pc.frame_start_found = 0; |
| 65 | continue; |
| 66 | } |
| 67 | ctx->pc.frame_start_found++; |
| 68 | ctx->remaining_size = ctx->fsize + i - 15; |
| 69 | if (ctx->pc.index + i > 15) { |
| 70 | next = i - 15; |
| 71 | state = 0; |
| 72 | break; |
| 73 | } else { |
| 74 | ctx->pc.state64 = 0; |
| 75 | goto restart; |
| 76 | } |
| 77 | } else if (ctx->pc.frame_start_found) |
| 78 | ctx->pc.frame_start_found++; |
| 79 | } |
| 80 | ctx->pc.state64 = state; |
| 81 | } else { |
| 82 | if (ctx->remaining_size) { |
| 83 | i = FFMIN(ctx->remaining_size, buf_size); |
| 84 | ctx->remaining_size -= i; |
| 85 | if (ctx->remaining_size) |
| 86 | goto flush; |
| 87 | |
| 88 | ctx->pc.frame_start_found = 0; |
| 89 | goto restart; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | flush: |
| 94 | if (ff_combine_frame(&ctx->pc, next, &buf, &buf_size) < 0) |
| 95 | return buf_size; |
nothing calls this directly
no test coverage detected