BUG: Reject transform names with no precision token#6608
Merged
hjmjohnson merged 1 commit intoJul 13, 2026
Merged
Conversation
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.
Contributor
|
| 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
dzenanz
approved these changes
Jul 13, 2026
hjmjohnson
approved these changes
Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TransformIOBaseTemplate::CorrectTransformPrecisionType()indexes a string with an uncheckedfind()result, so a transform-type name naming neither precision throwsstd::out_of_range— not anitk::ExceptionObject. Addresses B47 of #6575.Root cause
Both specializations (
itkTransformIOBase.h:187-207) do:When the name contains neither
"float"nor"double",begin == std::string::nposandstd::string::replacethrowsstd::out_of_range. That is a standard-library exception, so it propagates past every ITK handler — a caller doingcatch (itk::ExceptionObject &)around a transform read does not catch it, and the message (__pos (which is 18446744073709551615) > this->size()) names nothing useful.The
nposcase is now detected explicitly and raised asitkGenericExceptionMacronaming the offending transform-type string, matching the convention the unspecialized default already uses at:152. (itkExceptionMacrois unusable here — these arestaticmethods with nothis.)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 againstnposas 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 plusITKGoogleTesttoTEST_DEPENDS).CorrectTransformPrecisionTypeThrowsWithoutPrecisionToken— fail-before:std::out_of_range: basic_string::replace: __pos (which is 18446744073709551615) > this->size() (which is 20). Pass-after: throwsitk::ExceptionObject.CorrectTransformPrecisionTypeCorrectsMismatchedPrecision— control case; the normal float/double correction is unchanged, passes before and after.itkTransformFileReaderTest,itkTransformFileWriterTestpass, unchanged.AI assistance