Skip to contentSkip to conversation

media: v4l2-jpeg: ignore the unknown APP14 marker

PATCH In review Ming Qian 2 participants 3 messages Dec 16, 2022 – Feb 18, 2023 Media (V4L/DVB)

lore
Share & tools
lore

Ming Qian

author
#0 lore raw

PATCH 1/1 media: v4l2-jpeg: ignore the unknown APP14 marker

The legal identifier of APP14 is "Adobe\0",
but sometimes it may be
"This is an unknown APP marker . Compliant decoders must ignore it." In this case, just ignore it.
It won't affect the decode result.

Fixes b8035f7988a8 ("media: Add parsing for APP14 data segment in jpeg helpers")
---
 drivers/media/v4l2-core/v4l2-jpeg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-jpeg.c +1 -1
index 75c2af763d55..94435a7b6816 100644
@@ -460,7 +460,7 @@ static int jpeg_parse_app14_data(struct jpeg_stream *stream,
 	/* Check for "Adobe\0" in Ap1..6 */
 	if (stream->curr + 6 > stream->end ||
 	    strncmp(stream->curr, "Adobe\0", 6))
-		return -EINVAL;
+		return jpeg_skip(stream, lp - 2);
 
 	/* get to Ap12 */
 	ret = jpeg_skip(stream, 11);
Signature · 1 line
2.38.1
Reviewed-by Mirela Rabulea on v1 1/1
#1 lore raw

Hi,

Quoted 5 lines · Ming Qian

The legal identifier of APP14 is "Adobe\0",
but sometimes it may be
"This is an unknown APP marker . Compliant decoders must ignore it." In this case, just ignore it.
It won't affect the decode result.

I'm not sure, based on the specs only, what the decoders should do if the segment does not follow the definition.

I only found this in T.81:
"The APPn (Application) segments are reserved for application use. Since these segments may be defined differently for different applications, they should be removed when the data are exchanged between application environments."

And in T.872, the mention about "Adobe\0".

But, I agree ignoring it is more robust, and I confirm imx-jpeg can decode such jpegs.

Quoted 20 lines
Fixes b8035f7988a8 ("media: Add parsing for APP14 data segment in jpeg helpers")
---
  drivers/media/v4l2-core/v4l2-jpeg.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-jpeg.c +1 -1
index 75c2af763d55..94435a7b6816 100644
@@ -460,7 +460,7 @@ static int jpeg_parse_app14_data(struct jpeg_stream *stream,
  	/* Check for "Adobe\0" in Ap1..6 */
  	if (stream->curr + 6 > stream->end ||
  	    strncmp(stream->curr, "Adobe\0", 6))
-		return -EINVAL;
+		return jpeg_skip(stream, lp - 2);
 
  	/* get to Ap12 */
  	ret = jpeg_skip(stream, 11);
Reviewed-by Mirela Rabulea on v1 1/1
#2 lore raw
In reply to Ming Qian
Quoted 8 lines · Ming Qian

The legal identifier of APP14 is "Adobe\0",
but sometimes it may be
"This is an unknown APP marker . Compliant decoders must ignore it." In this case, just ignore it.
It won't affect the decode result.

Fixes b8035f7988a8 ("media: Add parsing for APP14 data segment in jpeg helpers")

Thanks,

Quoted 17 lines
---
  drivers/media/v4l2-core/v4l2-jpeg.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-jpeg.c +1 -1
index 75c2af763d55..94435a7b6816 100644
@@ -460,7 +460,7 @@ static int jpeg_parse_app14_data(struct jpeg_stream *stream,
  	/* Check for "Adobe\0" in Ap1..6 */
  	if (stream->curr + 6 > stream->end ||
  	    strncmp(stream->curr, "Adobe\0", 6))
-		return -EINVAL;
+		return jpeg_skip(stream, lp - 2);
 
  	/* get to Ap12 */
  	ret = jpeg_skip(stream, 11);