[PATCH v2 0/4] media: v4l2-jpeg: fix the segment length handling of the DHT, DQT and APP14 parsers
From: Arun Iyengar via B4 Relay
Date: Sat Dec 05 2026 - 04:24:53 EST
The DHT parser steps back two bytes at the end of every segment, and
neither the DHT nor the DQT parser skips bytes left after the last
table. Philipp Zabel pointed out the right DHT fix and the DQT problem
in his review of v1. The APP14 parser steps back on a segment that is
too short.
1/4: DHT: skip the rest of the segment, reject a table longer than it.
2/4: DQT: require 129 bytes for a table with 16-bit elements.
3/4: DQT: skip the rest of the segment.
4/4: APP14: reject a length below 2, or below 14 in an Adobe segment.
Tested on an Orange Pi Zero2 with the cedrus driver and a JPEG decoder
for it that is not in mainline and uses v4l2_jpeg_parse_header().
Patches 1-3: 14 of 14 cases pass, among them a DHT ending in FF C4 and
DHT and DQT segments with trailing bytes (decoded output identical to
the plain file), and a DHT table longer than its segment (rejected).
This decoder refuses every 16-bit DQT, so 2/4 was checked with the
parser built in userspace: a 16-bit table in a 67-byte segment returns
-EINVAL.
4/4: APP14 segments of length 0 and 1 and Adobe segments of length 8 and
13 are rejected; a full Adobe APP14 file decodes identical to the plain file.
Claude (Anthropic) wrote the patches and the commit messages; I reviewed them and tested as above.
---
Changes in v2:
- 1/4: skip len bytes instead of returning 0 (Philipp); reject a table longer than the segment.
- 2/4, 3/4, 4/4: new.
- Link to v1: https://patch.msgid.link/20261201-v4l2-jpeg-dht-rewind-v1-1-edf8b91a5c0f@xxxxxxxxx
---
Arun Iyengar (4):
media: v4l2-jpeg: do not rewind the stream after Huffman tables
media: v4l2-jpeg: check the segment length for 16-bit quantization tables
media: v4l2-jpeg: skip the rest of a quantization table segment
media: v4l2-jpeg: reject APP14 segments that are too short
drivers/media/v4l2-core/v4l2-jpeg.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
---
base-commit: fd568e1139cc43b39fad1108463d1f7681d82ce2
change-id: 20261201-v4l2-jpeg-dht-rewind-7b1b800d9ace
Best regards,
--
Arun Iyengar <aiyengar1990@xxxxxxxxx>