[PATCH v2 2/4] media: v4l2-jpeg: check the segment length for 16-bit quantization tables

From: Arun Iyengar via B4 Relay

Date: Sat Dec 05 2026 - 04:24:41 EST


From: Arun Iyengar <aiyengar1990@xxxxxxxxx>

The table loop only makes sure that 65 bytes are left in the segment,
but a table with 16-bit elements takes 129. Such a table at the end of
a short segment is read past the end of the segment.

Fixes: 50733b5b9102 ("media: add v4l2 JPEG helpers")
Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
drivers/media/v4l2-core/v4l2-jpeg.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-jpeg.c b/drivers/media/v4l2-core/v4l2-jpeg.c
index ee2b4d91d6086..f900e29f9a84d 100644
--- a/drivers/media/v4l2-core/v4l2-jpeg.c
+++ b/drivers/media/v4l2-core/v4l2-jpeg.c
@@ -453,6 +453,9 @@ static int jpeg_parse_quantization_tables(struct jpeg_stream *stream,
if (tq > 3)
return -EINVAL;

+ if (len < (pq ? 129 : 65))
+ return -EINVAL;
+
/* quantization table element */
qk = stream->curr;
ret = jpeg_skip(stream, pq ? 128 : 64);

--
2.55.0