BUG: Use check_symbol_exists for TIFFFieldReadCount detection#6150
Conversation
check_type_size on a function name fails on MSVC, causing crashes with system TIFF on Windows. Fixes InsightSoftwareConsortium#6148.
|
/azp run ITK.macOS |
|
@greptile Review this PR. |
|
| Filename | Overview |
|---|---|
| Modules/ThirdParty/TIFF/CMakeLists.txt | Replaces check_type_size(TIFFFieldReadCount …) with check_symbol_exists(TIFFFieldReadCount "tiffio.h" …) and adds include(CheckSymbolExists); CMAKE_REQUIRED_LIBRARIES and the check_type_size(TIFFField* …) call are left intact and correct. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[CMake configure with ITK_USE_SYSTEM_TIFF=ON] --> B[find_package TIFF::TIFF]
B --> C[include CheckSymbolExists]
C --> D["check_symbol_exists(TIFFFieldReadCount tiffio.h ...)"]
D -->|Symbol found| E[ITK_TIFF_HAS_TIFFFieldReadCount = 1]
D -->|Symbol not found| F[ITK_TIFF_HAS_TIFFFieldReadCount unset]
E --> G[check_type_size TIFFField*]
F --> G
G --> H[configure_file itk_tiff.h.in → itk_tiff.h]
H -->|ITK_TIFF_HAS_TIFFFieldReadCount defined| I[itkTIFFImageIO uses TIFFFieldReadCount API]
H -->|Not defined| J[itkTIFFImageIO falls back to legacy _TIFFField struct access → crashes with modern libtiff]
Reviews (2): Last reviewed commit: "BUG: Use check_symbol_exists for TIFFFie..." | Re-trigger Greptile
When building with ITK_USE_SYSTEM_TIFF=ON, check_type_size() was used to detect TIFFFieldReadCount (a function, not a type). Passing a function to sizeof() is non-standard and silently fails on MSVC, leaving ITK_TIFF_HAS_TIFFFieldReadCount undefined and causing itkTIFFImageIO to fall through to a stale libtiff 4.0.0-4.0.2 workaround that accesses an obsolete internal _TIFFField struct, causing NULL pointer crashes. Fixes: InsightSoftwareConsortium/ITK#6148 Upstream PR: InsightSoftwareConsortium/ITK#6150
When building with ITK_USE_SYSTEM_TIFF=ON, check_type_size() was used to detect TIFFFieldReadCount (a function, not a type). Passing a function to sizeof() is non-standard and silently fails on MSVC, leaving ITK_TIFF_HAS_TIFFFieldReadCount undefined and causing itkTIFFImageIO to fall through to a stale libtiff 4.0.0-4.0.2 workaround that accesses an obsolete internal _TIFFField struct, causing NULL pointer crashes. Fixes: InsightSoftwareConsortium/ITK#6148 Upstream PR: InsightSoftwareConsortium/ITK#6150
ccb17dc
into
InsightSoftwareConsortium:release-5.4
Summary
Fixes #6148.
When building with a system TIFF library (
ITK_USE_SYSTEM_TIFF=ON), the CMake check forTIFFFieldReadCountusedcheck_type_size(), which internally callssizeof()on the argument. Passing a function name tosizeof()is non-standard — GCC and Clang accept it as an extension but MSVC rejects it — soITK_TIFF_HAS_TIFFFieldReadCountwas never defined on Windows builds using an external libTIFF.Without that define,
itkTIFFImageIOfalls through to the libtiff 4.0.0–4.0.2 workaround that directly accesses the internal_TIFFFieldstruct. That struct layout is no longer correct for modern libtiff versions, causing reads of garbage data and NULL pointer crashes when encountering tags with unsupported data types (e.g. an ICC profile tag).Fix
Replace
check_type_size(TIFFFieldReadCount ...)withcheck_symbol_exists(TIFFFieldReadCount "tiffio.h" ...), which correctly detects the function on all compilers including MSVC.