Skip to content

Commit 816ab93

Browse files
authored
fix(jpeg): be a little more flexible with corrupt IPTC blocks (#5140)
Recent PR #5081 added more detection of corruptions in (among other places) the IPTC blocks in a JPEG file. But we maybe got a little too aggressive, since there appear to be some jpg files out there that have strange (maybe technically incorrect?) IPTC blocks but are otherwise fine. Anyway, I noticed that for ICC profiles in JPEG files, we use the OIIO attribute "imageinput:strict" to decide whether a localized corruption in the ICC profile ONLY causes the ICC profile to be skipped (reading the pixels just fine), or a stricter mode where anything suspicious is grounds to stop reading the file entirely and declare it corrupt. So in this patch, I'm using the same control for the analogous purpose when reading the IPTC blocks. By default, just skip the IPTC block if we don't know how to decode it. But if in strict mode, make a full error that will cause us to stop reading the file. With this change, I needed to update the jpeg-corrupt test to force strict node, and update some some ref outputs. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent c966232 commit 816ab93

File tree

7 files changed

+16
-29
lines changed

7 files changed

+16
-29
lines changed

src/jpeg.imageio/jpeginput.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@ JpgInput::open(const std::string& name, ImageSpec& newspec)
284284
decode_xmp(xml, m_spec);
285285
} else if (m->marker == (JPEG_APP0 + 13) && m->data_length >= 13
286286
&& !strncmp((const char*)m->data, "Photoshop 3.0", 13)) {
287-
if (!jpeg_decode_iptc(
288-
string_view((const char*)m->data, m->data_length))) {
287+
bool ok = jpeg_decode_iptc(
288+
string_view((const char*)m->data, m->data_length));
289+
if (!ok && OIIO::get_int_attribute("imageinput:strict")) {
289290
errorfmt("Corrupted IPTC data");
290291
return false;
291292
}

testsuite/jpeg-corrupt/ref/out-alt.txt

Lines changed: 0 additions & 22 deletions
This file was deleted.

testsuite/jpeg-corrupt/ref/out-alt2.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ src/corrupt-icc-4552.jpg : 1500 x 1000, 3 channel, uint8 jpeg
4444
ICCProfile:rendering_intent: "Unknown"
4545
jpeg:subsampling: "4:2:0"
4646
oiio:ColorSpace: "srgb_rec709_scene"
47-
iinfo ERROR: "src/corrupt-iptc-8011.jpg" : JPEG error: Corrupt JPEG data: 256 extraneous bytes before marker 0xdb ("src/corrupt-iptc-8011.jpg")
47+
oiiotool ERROR: read : JPEG error: Corrupt JPEG data: 256 extraneous bytes before marker 0xdb ("src/corrupt-iptc-8011.jpg")
4848
Corrupted IPTC data
49+
Full command line was:
50+
> oiiotool -oiioattrib imageinput:strict 1 -info -v src/corrupt-iptc-8011.jpg

testsuite/jpeg-corrupt/ref/out-alt3.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ src/corrupt-icc-4552.jpg : 1500 x 1000, 3 channel, uint8 jpeg
4343
ICCProfile:rendering_intent: "Unknown"
4444
jpeg:subsampling: "4:2:0"
4545
oiio:ColorSpace: "srgb_rec709_scene"
46-
iinfo ERROR: "src/corrupt-iptc-8011.jpg" : JPEG error: Corrupt JPEG data: 256 extraneous bytes before marker 0xdb ("src/corrupt-iptc-8011.jpg")
46+
oiiotool ERROR: read : JPEG error: Corrupt JPEG data: 256 extraneous bytes before marker 0xdb ("src/corrupt-iptc-8011.jpg")
4747
Corrupted IPTC data
48+
Full command line was:
49+
> oiiotool -oiioattrib imageinput:strict 1 -info -v src/corrupt-iptc-8011.jpg

testsuite/jpeg-corrupt/ref/out-alt4.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ src/corrupt-icc-4552.jpg : 1500 x 1000, 3 channel, uint8 jpeg
4444
ICCProfile:rendering_intent: "Unknown"
4545
jpeg:subsampling: "4:2:0"
4646
oiio:ColorSpace: "srgb_rec709_scene"
47-
iinfo ERROR: "src/corrupt-iptc-8011.jpg" : JPEG error: Corrupt JPEG data: 256 extraneous bytes before marker 0xdb ("src/corrupt-iptc-8011.jpg")
47+
oiiotool ERROR: read : JPEG error: Corrupt JPEG data: 256 extraneous bytes before marker 0xdb ("src/corrupt-iptc-8011.jpg")
4848
Corrupted IPTC data
49+
Full command line was:
50+
> oiiotool -oiioattrib imageinput:strict 1 -info -v src/corrupt-iptc-8011.jpg

testsuite/jpeg-corrupt/ref/out.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ src/corrupt-icc-4552.jpg : 1500 x 1000, 3 channel, uint8 jpeg
4444
ICCProfile:rendering_intent: "Unknown"
4545
jpeg:subsampling: "4:2:0"
4646
oiio:ColorSpace: "srgb_rec709_scene"
47-
iinfo ERROR: "src/corrupt-iptc-8011.jpg" : JPEG error: Corrupt JPEG data: 256 extraneous bytes before marker 0xdb ("src/corrupt-iptc-8011.jpg")
47+
oiiotool ERROR: read : JPEG error: Corrupt JPEG data: 256 extraneous bytes before marker 0xdb ("src/corrupt-iptc-8011.jpg")
4848
Corrupted IPTC data
49+
Full command line was:
50+
> oiiotool -oiioattrib imageinput:strict 1 -info -v src/corrupt-iptc-8011.jpg

testsuite/jpeg-corrupt/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
command += info_command ("src/corrupt-icc-4552.jpg", safematch=True)
2727

2828
# This file had corrupted IPTC data
29-
command += info_command ("-v src/corrupt-iptc-8011.jpg", info_program="iinfo")
29+
command += oiiotool("-oiioattrib imageinput:strict 1 -info -v src/corrupt-iptc-8011.jpg")

0 commit comments

Comments
 (0)