Skip to content

fix(jpeg): be a little more flexible with corrupt IPTC blocks#5140

Merged
lgritz merged 1 commit intoAcademySoftwareFoundation:mainfrom
lgritz:lg-iptcstrict
Apr 13, 2026
Merged

fix(jpeg): be a little more flexible with corrupt IPTC blocks#5140
lgritz merged 1 commit intoAcademySoftwareFoundation:mainfrom
lgritz:lg-iptcstrict

Conversation

@lgritz
Copy link
Copy Markdown
Collaborator

@lgritz lgritz commented Apr 11, 2026

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.

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 don't have correct IPTC blocks but are
otherwise fine. Well, the IPTC block may be bad, but nothing else is
wrong with the file. I don't want to point fingers, but maybe it's
PhotoShop writing the strange IPTC blocks (maybe many years old
versions).

Anyway, I noticed that we take the following approach with 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 if anything suspicious is grounds to stop reading the file entirely
and declare it corrupt.

So 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, drop it immeditely and run
away.

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>
@lgritz lgritz added bug Crash or wrong behavior of an existing feature. file formats Image file formats, ImageInput, ImageOutput labels Apr 11, 2026
@lgritz
Copy link
Copy Markdown
Collaborator Author

lgritz commented Apr 13, 2026

I need this at work, if any has time to give it a review

Copy link
Copy Markdown
Contributor

@aconty aconty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lgritz lgritz merged commit 816ab93 into AcademySoftwareFoundation:main Apr 13, 2026
31 checks passed
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Apr 13, 2026
…ySoftwareFoundation#5140)

Recent PR AcademySoftwareFoundation#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>
@lgritz lgritz deleted the lg-iptcstrict branch April 15, 2026 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Crash or wrong behavior of an existing feature. file formats Image file formats, ImageInput, ImageOutput

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants