Skip to content

BUG: Fix the REJECT_COMPLEX path in nifti_image_read - #132

Open
hjmjohnson wants to merge 3 commits into
stack/pr-fix-shorten-64-to-32from
stack/fix-image-read-complex-check
Open

hjmjohnson wants to merge 3 commits into
stack/pr-fix-shorten-64-to-32from
stack/fix-image-read-complex-check

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Re-submission of #74, reverted from master on 2026-09-24. Content is
unchanged from the original.

Position 10 of 11 in the deep stack. Base: stack/pr-fix-shorten-64-to-32.

Based on the pull request above it in the stack, so the diff shown here is
this change alone. Merge the stack bottom-up.

Stack order

# branch base
1 stack/test-regression-coverage master
2 stack/pr-fix-alloc-null-checks stack/test-regression-coverage
3 stack/fix-axml-skip-depth stack/pr-fix-alloc-null-checks
4 stack/pr-fix-analyzer-leaks stack/fix-axml-skip-depth
5 stack/pr-fix-sign-conversion stack/pr-fix-analyzer-leaks
6 stack/fix-fslio-64bit-arithmetic stack/pr-fix-sign-conversion
7 stack/fix-cifti-null-stream stack/fix-fslio-64bit-arithmetic
8 stack/pr-fix-calloc-transposed-args stack/fix-cifti-null-stream
9 stack/pr-fix-shorten-64-to-32 stack/pr-fix-calloc-transposed-args
10 stack/fix-image-read-complex-check <- this PR stack/pr-fix-shorten-64-to-32
11 stack/pr-fix-xml-read-errors stack/fix-image-read-complex-check

The order is the order these changes sat on master before the revert, so
it builds and tests at every step.

Commits introduced by this PR
  • BUG: Return from the REJECT_COMPLEX path instead of calling exit()
  • ENH: Test that a complex image is rejected without ending the process

Ordering for all the re-submitted work is tracked in #84.

gdevenyi and others added 3 commits September 24, 2026 07:12
Clears all 155 bugprone-macro-parentheses findings: 152 in
nifti2/nifti_tool.c, 2 in niftilib/nifti1_tool.c, 1 in fsliolib/fslio.c.

An unparenthesized argument takes the precedence of whatever the caller
passed. NT_FILL(..., rv) expands to `rv = ...` and NT_MAT33_TO_MAT44 to
`m44.m[0][0] = ...`, which break for an argument that is not already a
postfix expression. Every current caller passes a plain identifier, a
literal or `nim->sto_xyz`, so nothing observable moves.

The NT_DCONVERT dtype and stype parameters stay bare behind a NOLINT
fence: they name types, so `(dtype) * pd = dptr;` would be a cast
expression rather than a declaration. FSL_RADIOLOGICAL is in an installed
header, so its replacement list changes from -1 to (-1); its value does not.

(cherry picked from commit dbfb59d)
nifti_image_read() ended the calling process with exit(13) when it met
a complex datatype, leaking the open file and hfile on the way out.  A
library reports the condition to its caller: the block now frees the
image, closes the file, releases hfile and returns NULL, which is how
every other rejection in the function behaves.

The message also loses its "64", which was wrong for the 128 and 256
cases.

REJECT_COMPLEX is off by default but is supported: -DFSLSTYLE:BOOL=ON
turns it on, and nifti2/Makefile defines it always.

(cherry picked from commit c8a10fe)
Writes a DT_COMPLEX64 image and a DT_FLOAT32 image, then asserts
nifti_image_read() returns NULL for the first and a usable image for
the second, so a blanket refusal cannot pass.  Registered only when
FSLSTYLE_REJECT_COMPLEX is on.  Against exit(13) the test process dies
with status 13 before reaching either assertion.

(cherry picked from commit 461cd33)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants