diff mbox series

[FFmpeg-devel,2/2] avcodec/jpegxl_parser: fix parsing sequences of extremely small files

Message ID 20231123234541.41316-3-leo.izen@gmail.com
State New
Headers show
Series JPEG XL parser bug fixes | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Leo Izen Nov. 23, 2023, 11:45 p.m. UTC
This patch allows the JXL parser to parse sequences of extremely small
files concatenated together. (e.g. smaller than the parser buffer)

Signed-off-by: Leo Izen <leo.izen@gmail.com>
---
 libavcodec/jpegxl_parser.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Anton Khirnov Nov. 26, 2023, 10:56 a.m. UTC | #1
Would be nice to have tests for these.
Leo Izen Nov. 26, 2023, 1:47 p.m. UTC | #2
On 11/26/23 05:56, Anton Khirnov wrote:
> Would be nice to have tests for these.
> 

I have a sample at: https://buzo.us/l.jxl

It would test both of these patches. I can send a fate test for these to 
the ML if the sample gets uploaded. I CC'd samples-request@ffmpeg.org as 
well.

- Leo Izen (Traneptora)
Thilo Borgmann Nov. 26, 2023, 6:07 p.m. UTC | #3
> Am 26.11.2023 um 14:47 schrieb Leo Izen <leo.izen@gmail.com>:
> On 11/26/23 05:56, Anton Khirnov wrote:
>> Would be nice to have tests for these.
> 
> I have a sample at: https://buzo.us/l.jxl
> 
> It would test both of these patches. I can send a fate test for these to the ML if the sample gets uploaded. I CC'd samples-request@ffmpeg.org as well.

Can do this in a bit. What about the file you‘d sent to samples-request in August, is there still a test to be pushed about it as well?

-Thilo
Leo Izen Nov. 26, 2023, 11:33 p.m. UTC | #4
On 11/26/23 13:07, Thilo Borgmann wrote:
> 
> 
>> Am 26.11.2023 um 14:47 schrieb Leo Izen <leo.izen@gmail.com>:
>> On 11/26/23 05:56, Anton Khirnov wrote:
>>> Would be nice to have tests for these.
>>
>> I have a sample at: https://buzo.us/l.jxl
>>
>> It would test both of these patches. I can send a fate test for these to the ML if the sample gets uploaded. I CC'd samples-request@ffmpeg.org as well.
> 
> Can do this in a bit. What about the file you‘d sent to samples-request in August, is there still a test to be pushed about it as well?
> 
> -Thilo

There is not, that sample from August was already uploaded and the fate 
test utilizing it has been merged.

- Leo Izen (Traneptora)
Thilo Borgmann Nov. 27, 2023, 9:49 a.m. UTC | #5
On 27.11.23 00:33, Leo Izen wrote:
> On 11/26/23 13:07, Thilo Borgmann wrote:
>>
>>
>>> Am 26.11.2023 um 14:47 schrieb Leo Izen <leo.izen@gmail.com>:
>>> On 11/26/23 05:56, Anton Khirnov wrote:
>>>> Would be nice to have tests for these.
>>>
>>> I have a sample at: https://buzo.us/l.jxl
>>>
>>> It would test both of these patches. I can send a fate test for 
>>> these to the ML if the sample gets uploaded. I CC'd 
>>> samples-request@ffmpeg.org as well.
>>
>> Can do this in a bit. What about the file you‘d sent to 
>> samples-request in August, is there still a test to be pushed about 
>> it as well?
>>
>> -Thilo
>
> There is not, that sample from August was already uploaded and the 
> fate test utilizing it has been merged.

Ok, then its done:

e19bb66167c096e86f8cf567a7df3528  fate-suite/jxl/l.jxl

-Thilo
diff mbox series

Patch

diff --git a/libavcodec/jpegxl_parser.c b/libavcodec/jpegxl_parser.c
index 750872f17f..006eb6b295 100644
--- a/libavcodec/jpegxl_parser.c
+++ b/libavcodec/jpegxl_parser.c
@@ -1454,15 +1454,21 @@  static int jpegxl_parse(AVCodecParserContext *s, AVCodecContext *avctx,
 {
     JXLParseContext *ctx = s->priv_data;
     int next = END_NOT_FOUND, ret;
+    const uint8_t *pbuf = ctx->pc.buffer;
+    int pindex = ctx->pc.index;
 
     *poutbuf_size = 0;
     *poutbuf = NULL;
 
-    if (!ctx->pc.index)
-        goto flush;
+    if (!ctx->pc.index) {
+        if (ctx->pc.overread)
+            goto flush;
+        pbuf = buf;
+        pindex = buf_size;
+    }
 
     if ((!ctx->container || !ctx->codestream_length) && !ctx->next) {
-        ret = try_parse(s, avctx, ctx, ctx->pc.buffer, ctx->pc.index);
+        ret = try_parse(s, avctx, ctx, pbuf, pindex);
         if (ret < 0)
             goto flush;
         ctx->next = ret;
@@ -1471,7 +1477,7 @@  static int jpegxl_parse(AVCodecParserContext *s, AVCodecContext *avctx,
     }
 
     if (ctx->container && ctx->next >= 0) {
-        ret = skip_boxes(ctx, ctx->pc.buffer, ctx->pc.index);
+        ret = skip_boxes(ctx, pbuf, pindex);
         if (ret < 0) {
             if (ret == AVERROR_INVALIDDATA)
                 ctx->next = -1;