Skip to content

Commit 5e005e6

Browse files
authored
fix(tiff): Fix TIFF output crash for multi-count Exif metadata (#5035)
Fixes #5023 This was crashing when writing TIFF information that was supposed to be arrays of more than one rational, but in fact was provided as a single value, it was reading past the end of a memory array. I noticed that this whole region needs a cleanup, this is not the only problem. But a full overhaul seems too risky to backport, so my strategy is as follows: * THIS fix first, which I will backport right away to 3.0 and 3.1. * I will then submit a separate PR (already implemented and tested) that is a much more complete fix and overhaul of this portion of the code (and other places). That will get merged into main when approved. * After the second PR is merged, I'll hold it in main for a while to test its safety, and then decide if it seems ok to backport to 3.1 (but definitely not 3.0). Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent ee3370d commit 5e005e6

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/tiff.imageio/tiffoutput.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,16 +1141,16 @@ TIFFOutput::write_exif_data()
11411141
if (tifftype == TIFF_ASCII) {
11421142
ok = TIFFSetField(m_tif, tag, *(char**)p.data());
11431143
} else if ((tifftype == TIFF_SHORT || tifftype == TIFF_LONG)
1144-
&& p.type() == TypeDesc::SHORT) {
1144+
&& p.type() == TypeDesc::SHORT && count == 1) {
11451145
ok = TIFFSetField(m_tif, tag, (int)*(short*)p.data());
11461146
} else if ((tifftype == TIFF_SHORT || tifftype == TIFF_LONG)
1147-
&& p.type() == TypeDesc::INT) {
1147+
&& p.type() == TypeDesc::INT && count == 1) {
11481148
ok = TIFFSetField(m_tif, tag, *(int*)p.data());
11491149
} else if ((tifftype == TIFF_RATIONAL || tifftype == TIFF_SRATIONAL)
1150-
&& p.type() == TypeDesc::FLOAT) {
1150+
&& p.type() == TypeDesc::FLOAT && count == 1) {
11511151
ok = TIFFSetField(m_tif, tag, *(float*)p.data());
11521152
} else if ((tifftype == TIFF_RATIONAL || tifftype == TIFF_SRATIONAL)
1153-
&& p.type() == TypeDesc::DOUBLE) {
1153+
&& p.type() == TypeDesc::DOUBLE && count == 1) {
11541154
ok = TIFFSetField(m_tif, tag, *(double*)p.data());
11551155
}
11561156
if (!ok) {

0 commit comments

Comments
 (0)