[PATCH v2 1/4] media: v4l2-jpeg: do not rewind the stream after Huffman tables
From: Arun Iyengar via B4 Relay
Date: Sat Dec 05 2026 - 04:24:55 EST
From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
After the table loop len is the number of bytes left in the segment,
normally 0, so jpeg_skip(stream, len - 2) moves the stream back two
bytes and a table that ends in FF C4 fails with -EINVAL. Skip len
bytes instead, and reject a table that is longer than the segment,
which would leave len negative.
Fixes: 50733b5b9102 ("media: add v4l2 JPEG helpers")
Suggested-by: Philipp Zabel <p.zabel@xxxxxxxxxxxxxx>
Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
drivers/media/v4l2-core/v4l2-jpeg.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/media/v4l2-core/v4l2-jpeg.c b/drivers/media/v4l2-core/v4l2-jpeg.c
index 36a0f1a1b0d97..ee2b4d91d6086 100644
--- a/drivers/media/v4l2-core/v4l2-jpeg.c
+++ b/drivers/media/v4l2-core/v4l2-jpeg.c
@@ -514,6 +514,8 @@ static int jpeg_parse_huffman_tables(struct jpeg_stream *stream,
mt += li;
}
+ if (mt > len - 17)
+ return -EINVAL;
/* HUFFVAL - values associated with each Huffman code */
ret = jpeg_skip(stream, mt);
if (ret < 0)
@@ -525,7 +527,7 @@ static int jpeg_parse_huffman_tables(struct jpeg_stream *stream,
}
}
- return jpeg_skip(stream, len - 2);
+ return jpeg_skip(stream, len);
}
/* B.2.4.4 Restart interval definition syntax */
--
2.55.0