[Debian-med-packaging] nifti_image_load() returns NULL data pointer on ARM64

Alle Meije Wink a.m.wink at gmail.com
Mon Oct 6 12:36:22 BST 2025


Using a Ubuntu VM on an M1 MacBook, I found that nifti_image_load() returns NULL data pointer on ARM64 despite a seemingly successful read — according to the feedback (with debug level 5).

Affected Package
  libnifti2-dev
  Also tested with libnifti-dev (same result)
  Version tested: 3.0.1-9.1 on Ubuntu 24.04 ARM64

Problem Summary

When loading a .nii file using the documented nifti_image_read() / nifti_image_load() sequence, no voxel data is available: the data pointer remains NULL, even though the header loads and the file appears readable.

I can confirm:
  The .nii file is uncompressed, with size matching header expectations.
  nifti_read_buffer() reports reading the full expected byte count.
  The same file and code works perfectly on amd64.

1, Header Loads OK
nifti_image* img = nifti_image_read(path, 0);  // header only
nifti_image_load(img);                                     // load voxel data

img is valid.
img->nvox × img->nbyper = expected size (e.g. 11,927,552 bytes)

But img->data == nullptr after load.

Debug output shows:
+d nifti_read_buffer: read 11927552 bytes
+d in image, 0 bad floats were set to 0

Yet the data is never populated.

2. Workaround Works

Manually reading the buffer works fine:

img->data = malloc(nifti_get_volsize(img));
znzFile fp = znzopen(path, "rb", 1);
znzseek(fp, img->iname_offset, SEEK_SET);
size_t read = nifti_read_buffer(fp, img->data, img->nvox * img->nbyper, img);
znzclose(fp);

This correctly loads the voxel data, confirming that the image is valid and libznz + libz are functioning properly.

3. Hypotheses
Could it be a bug in nifti_image_load() or a conditional in nifti_image_read() that silently frees or ignores the buffer after reading?
Possibly an alignment / padding issue on ARM64?

The read count succeeds, but some validation or check might fail after the fact, clearing the pointer.
Since the same .nii file and code work fine on amd64, it may be specific to ARM64 pointer or size assumptions.

4. System Info
Ubuntu 24.04 on MacBook M1 14inch (ARM64) running Sonoma
Package: libnifti2-dev:arm64
File tested: brainT1.nii (uncompressed, 11927904 bytes)
Confirmed libznz.so.3, libz.so.1 are present (via ldd)
Reproduced with multiple .nii files

Files / Reproduction
Can provide .nii file (~11MB) if needed
Minimal C++ test case available
Full debug output from nifti_image_infodump() and nifti_read_buffer() available

Request
Could you help confirm:
Is this a known issue with libnifti2-dev on ARM64?
Any known fixes / patches?
Should this be filed against the upstream nifti_clib GitHub repo?
Thank you for maintaining this package — it’s incredibly helpful for neuroimaging teaching and research.

Best regards,
Alle Meije Wink


More information about the Debian-med-packaging mailing list