Skip to content

BUG: Reject transform names with no precision token#6608

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
physwkim:bug-transformio-precision-substring-6575
Jul 13, 2026
Merged

BUG: Reject transform names with no precision token#6608
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
physwkim:bug-transformio-precision-substring-6575

Conversation

@physwkim

Copy link
Copy Markdown
Contributor

TransformIOBaseTemplate::CorrectTransformPrecisionType() indexes a string with an unchecked find() result, so a transform-type name naming neither precision throws std::out_of_range — not an itk::ExceptionObject. Addresses B47 of #6575.

Root cause

Both specializations (itkTransformIOBase.h:187-207) do:

auto begin = inputTransformName.find("float");
inputTransformName.replace(begin, 5, "double");

When the name contains neither "float" nor "double", begin == std::string::npos and std::string::replace throws std::out_of_range. That is a standard-library exception, so it propagates past every ITK handler — a caller doing catch (itk::ExceptionObject &) around a transform read does not catch it, and the message (__pos (which is 18446744073709551615) > this->size()) names nothing useful.

The npos case is now detected explicitly and raised as itkGenericExceptionMacro naming the offending transform-type string, matching the convention the unspecialized default already uses at :152. (itkExceptionMacro is unusable here — these are static methods with no this.)

Anchor rg -n 'find\(' Modules/IO/TransformBase/: the other hits (itkTransformFileReader.cxx:173, itkCompositeTransformIOHelper.cxx:154-155,190-191, itkTransformFileWriterSpecializations.cxx:102,277) all compare the result against npos as a boolean guard and never index with it — distinct, not touched.

Local validation

New GoogleTest itkTransformIOBaseGTest.cxx (the module had no GTest driver; added the block plus ITKGoogleTest to TEST_DEPENDS).

  • CorrectTransformPrecisionTypeThrowsWithoutPrecisionToken — fail-before: std::out_of_range: basic_string::replace: __pos (which is 18446744073709551615) > this->size() (which is 20). Pass-after: throws itk::ExceptionObject.
  • CorrectTransformPrecisionTypeCorrectsMismatchedPrecision — control case; the normal float/double correction is unchanged, passes before and after.
  • itkTransformFileReaderTest, itkTransformFileWriterTest pass, unchanged.
AI assistance

CorrectTransformPrecisionType used an unchecked find() result to
index into replace(). A transform-type name naming neither
precision threw std::out_of_range, which is not an
itk::ExceptionObject and bypasses ITK exception handling.

Addresses item B47 of InsightSoftwareConsortium#6575.
@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:IO Issues affecting the IO module labels Jul 13, 2026
@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes malformed transform precision names fail through ITK exceptions. The main changes are:

  • Added npos checks before replacing float or double tokens.
  • Added a GoogleTest dependency for the TransformBase tests.
  • Added a new GoogleTest driver for itkTransformIOBase coverage.
  • Added tests for missing precision tokens and normal precision correction.

Confidence Score: 5/5

This looks safe to merge.

No blocking issues found in the changed code.

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex attempted to configure the project and found that cmake, ctest, and ninja were not available in the environment, while make, gcc, g++, and c++ were present.
  • A focused compile/test attempt proceeded but was blocked by a missing ITKIOTransformBaseExport.h header, leading to a fatal error during the build.
  • As a result, no configured build tree could be generated and the new itkTransformIOBaseGTest cases along with unchanged reader/writer tests could not be executed.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
Modules/IO/TransformBase/include/itkTransformIOBase.h Adds explicit missing-token checks before precision replacement.
Modules/IO/TransformBase/itk-module.cmake Adds ITKGoogleTest as a test dependency.
Modules/IO/TransformBase/test/CMakeLists.txt Registers a new GoogleTest driver for TransformBase tests.
Modules/IO/TransformBase/test/itkTransformIOBaseGTest.cxx Adds focused tests for malformed and corrected transform precision names.

Reviews (1): Last reviewed commit: "BUG: Reject transform names with no prec..." | Re-trigger Greptile

@hjmjohnson hjmjohnson merged commit b859c33 into InsightSoftwareConsortium:main Jul 13, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:IO Issues affecting the IO module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants