Re: [PATCH] media: v4l2-jpeg: do not rewind the stream after Huffman tables
From: Philipp Zabel
Date: Tue Dec 01 2026 - 11:22:19 EST
On Di, 2026-12-01 at 15:29 +0000, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
>
> After the table loop len is normally 0, so jpeg_skip(stream, len - 2)
> moves the stream back two bytes and the next marker search rescans the
> end of the last table.
>
> Return 0, as the quantization table parser does.
I think the DQT parser is wrong. If there is remaining len, it should
skip over it.
> Fixes: 50733b5b9102 ("media: add v4l2 JPEG helpers")
> Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
> ---
> Host test, parser built in userspace: a DHT ending in FF C4 gives -EINVAL
> before and 0 after; a normal header parses the same.
I expect you can trigger the same -EINVAL by adding a DHT segment
header to the end of a DQT right now.
> arm64 allmodconfig W=1 build is clean. Not run on coda hardware.
>
> Developed with Claude (Anthropic) as a coding assistant, which wrote the
> code and this message. I reviewed it.
> ---
> drivers/media/v4l2-core/v4l2-jpeg.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-jpeg.c b/drivers/media/v4l2-core/v4l2-jpeg.c
> index 36a0f1a1b0d9..8b80f4b5311b 100644
> --- a/drivers/media/v4l2-core/v4l2-jpeg.c
> +++ b/drivers/media/v4l2-core/v4l2-jpeg.c
> @@ -525,7 +525,7 @@ static int jpeg_parse_huffman_tables(struct jpeg_stream *stream,
> }
> }
>
> - return jpeg_skip(stream, len - 2);
> + return 0;
The error here is that this tries to subtract the two bytes for the
segment length value again. Those were already subtracted at the start
of the for loop. Wouldn't
return jpeg_skip(stream, len);
be correct?
regards
Philipp