Skip to content

Conversation

@N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Jul 10, 2025

ImageIOBase::GetComponentTypeTraits incorrectly assumed that the plain char type is always mapped to IOComponentEnum::CHAR. However, that isn't the case when the default char type is an unsigned type (as can be specified by GCC option -funsigned-char and MSVC option /J).

This bug was introduced with pull request #5421 commit 3604e0c "ENH: Ease getting type traits of pixel components from ImageIO" (merged to the master branch on June 23, 2025).

The bug caused incorrect return values from the following function calls:

ImageIOBase::GetNumberOfBitsOfComponentType(IOComponentEnum::INT8);
ImageIOBase::GetNumberOfBitsOfComponentType(IOComponentEnum::CHAR);
ImageIOBase::GetComponentTypeFromTypeTraits(false, false, 0);
ImageIOBase::GetComponentTypeFromTypeTraits(false, false, 8);

As was observed from the static_assert failures in "itkImageIOBaseTest.cxx", when using the compiler option that makes the default char unsigned.


Note: The bug was my own fault 😺

`ImageIOBase::GetComponentTypeTraits` incorrectly assumed that the plain `char`
type is always mapped to `IOComponentEnum::CHAR`. However, that isn't the case
when the default `char` type is an unsigned type (as can be specified by GCC
option `-funsigned-char` and MSVC option `/J`).

This bug was introduced with pull request InsightSoftwareConsortium#5421
commit 3604e0c "ENH: Ease getting type traits of
pixel components from ImageIO" (merged to the master branch on June 23, 2025).

The bug caused incorrect return values from the following function calls:

    ImageIOBase::GetNumberOfBitsOfComponentType(IOComponentEnum::INT8);
    ImageIOBase::GetNumberOfBitsOfComponentType(IOComponentEnum::CHAR);
    ImageIOBase::GetComponentTypeFromTypeTraits(false, false, 0);
    ImageIOBase::GetComponentTypeFromTypeTraits(false, false, 8);

As was observed from the static_assert failures in "itkImageIOBaseTest.cxx",
when using the compiler option that makes the default `char` unsigned.
@github-actions github-actions bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances area:IO Issues affecting the IO module labels Jul 10, 2025
@N-Dekker N-Dekker marked this pull request as ready for review July 10, 2025 21:06
@hjmjohnson hjmjohnson merged commit eb4e3ae into InsightSoftwareConsortium:main Jul 11, 2025
19 of 22 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants