Skip to content

Commit 9d4da40

Browse files
lgritzssh4net
authored andcommitted
fix: Fix UB in exif parsing of corrupt data (AcademySoftwareFoundation#5113)
Corrupted exif data could put a value in a "tiff data type" field that is not one of the valid enum values. That's UB. Identified by running the sanitizer with a newer clang than we usually do. --------- Signed-off-by: Larry Gritz <lg@larrygritz.com> Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
1 parent 9a0d465 commit 9d4da40

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/include/OpenImageIO/tiffutils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ OIIO_NAMESPACE_3_1_BEGIN
159159
/// obvious equivalent.
160160
OIIO_API TypeDesc tiff_datatype_to_typedesc (TIFFDataType tifftype, size_t tiffcount=1);
161161

162-
inline TypeDesc tiff_datatype_to_typedesc (const TIFFDirEntry& dir) {
163-
return tiff_datatype_to_typedesc (TIFFDataType(dir.tdir_type), dir.tdir_count);
164-
}
162+
OIIO_API TypeDesc tiff_datatype_to_typedesc (const TIFFDirEntry& dir);
165163

166164
/// Return the data size (in bytes) of the TIFF type.
167165
OIIO_API size_t tiff_data_size (TIFFDataType tifftype);

src/libOpenImageIO/exif.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ tiff_data_size(const TIFFDirEntry& dir)
178178

179179

180180

181+
TypeDesc
182+
tiff_datatype_to_typedesc(const TIFFDirEntry& dir)
183+
{
184+
// Check for corrupt/invalid value
185+
#if defined(TIFF_VERSION_BIG)
186+
if (dir.tdir_type > TIFF_IFD8)
187+
#else
188+
if (dir.tdir_type > TIFF_IFD)
189+
#endif
190+
return TypeUnknown;
191+
return tiff_datatype_to_typedesc(TIFFDataType(dir.tdir_type),
192+
dir.tdir_count);
193+
}
194+
195+
196+
181197
TypeDesc
182198
tiff_datatype_to_typedesc(TIFFDataType tifftype, size_t tiffcount)
183199
{
@@ -208,6 +224,7 @@ tiff_datatype_to_typedesc(TIFFDataType tifftype, size_t tiffcount)
208224
case TIFF_SLONG8: return TypeDesc(TypeDesc::INT64, tiffcount);
209225
case TIFF_IFD8: return TypeUnknown;
210226
#endif
227+
default: break;
211228
}
212229
return TypeUnknown;
213230
}

0 commit comments

Comments
 (0)