This patch allows the JXL parser to parse sequences of extremely small files concatenated together. (e.g. smaller than the parser buffer)
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -1454,15 +1454,21 @@ static int jpegxl_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 1453 unmodified lines | ||
| 1454 | 1454 | { |
| 1455 | 1455 | JXLParseContext *ctx = s->priv_data; |
| 1456 | 1456 | int next = END_NOT_FOUND, ret; |
| 1457 | + const uint8_t *pbuf = ctx->pc.buffer; | |
| 1458 | + int pindex = ctx->pc.index; | |
| 1457 | 1459 | |
| 1458 | 1460 | *poutbuf_size = 0; |
| 1459 | 1461 | *poutbuf = NULL; |
| 1460 | 1462 | |
| 1461 | − if (!ctx->pc.index) | |
| 1462 | − goto flush; | |
| 1463 | + if (!ctx->pc.index) { | |
| 1464 | + if (ctx->pc.overread) | |
| 1465 | + goto flush; | |
| 1466 | + pbuf = buf; | |
| 1467 | + pindex = buf_size; | |
| 1468 | + } | |
| 1463 | 1469 | |
| 1464 | 1470 | if ((!ctx->container || !ctx->codestream_length) && !ctx->next) { |
| 1465 | − ret = try_parse(s, avctx, ctx, ctx->pc.buffer, ctx->pc.index); | |
| 1471 | + ret = try_parse(s, avctx, ctx, pbuf, pindex); | |
| 1466 | 1472 | if (ret < 0) |
| 1467 | 1473 | goto flush; |
| 1468 | 1474 | ctx->next = ret; |
| @@ -1471,7 +1477,7 @@ static int jpegxl_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 2 unmodified lines | ||
| 1471 | 1477 | } |
| 1472 | 1478 | |
| 1473 | 1479 | if (ctx->container && ctx->next >= 0) { |
| 1474 | − ret = skip_boxes(ctx, ctx->pc.buffer, ctx->pc.index); | |
| 1480 | + ret = skip_boxes(ctx, pbuf, pindex); | |
| 1475 | 1481 | if (ret < 0) { |
| 1476 | 1482 | if (ret == AVERROR_INVALIDDATA) |
| 1477 | 1483 | ctx->next = -1; |