From 07c38b27df7b488b8724882b996d17d7086d2662 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Fri, 14 Aug 2026 20:52:31 -0400 Subject: [PATCH] BUG: Compare NIfTI test output by content, not by compressed bytes nifti_c22_copy_image has been failing on this machine since before any of this work started. It converts an image i16 -> i64 -> i16 and asserts the result matches the original, using cmp out.c22.0.i16.nii.gz out.c22.2.0.i16.nii.gz That compares gzip output, which is not reproducible across zlib implementations. The system zlib here is zlib-ng 1.3.1, which Arch, CachyOS and a growing number of distributions ship in place of stock zlib; it encodes the same input differently. Both files come out at exactly 642454 bytes and differ from byte 321594 on. The conversion itself is fine. Decompressed, the two files are byte-identical at 1114768 bytes each, so the round-trip through int64 and back preserves the data exactly, which is what the test set out to check. Confirmed the other way too: in an Ubuntu 24.04 container with stock zlib 1.3, the test passes unmodified. The test now decompresses before comparing, via a small nii_cmp helper that falls back to plain cmp for uncompressed files. With this the suite is 92 of 92 on both zlib-ng and stock zlib; previously it was 91 of 92 on any zlib-ng system. (cherry picked from commit 7d92f16249b7545db8e0f22bedb0da767e7af75e) --- .../cmake_testscripts/c22_copy_image.sh | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/nifti2/nifti_regress_test/cmake_testscripts/c22_copy_image.sh b/nifti2/nifti_regress_test/cmake_testscripts/c22_copy_image.sh index a3abddc2..18c435c9 100644 --- a/nifti2/nifti_regress_test/cmake_testscripts/c22_copy_image.sh +++ b/nifti2/nifti_regress_test/cmake_testscripts/c22_copy_image.sh @@ -11,6 +11,23 @@ DATA=$2 OUT_DATA=$(dirname ${DATA}) #Need to write to separate directory cd ${OUT_DATA} + +# Compare two NIfTI files by content rather than by compressed bytes. +# +# gzip output is not reproducible across zlib implementations: zlib-ng, +# which Arch, CachyOS and other current distributions ship as the system +# zlib, encodes the same input differently from stock zlib. Comparing +# the .gz files directly therefore fails on those systems even though the +# image data round-trips perfectly. Decompress first and compare that. +nii_cmp() { + if [ "${1##*.}" = "gz" ]; then + gzip -dc "$1" > "$1.raw" && gzip -dc "$2" > "$2.raw" || return 1 + cmp "$1.raw" "$2.raw" + return $? + fi + cmp "$1" "$2" +} + # note the main input file and prefix for all output files infile=$DATA/e4.60005.nii.gz prefix=out.c22 @@ -42,7 +59,7 @@ ${NT} -copy_image -infile ${prefix}.0.i16.nii.gz \ ${NT} -copy_image -infile ${prefix}.1.i64.nii.gz \ -prefix ${prefix}.2.0.i16.nii.gz \ -convert2dtype NIFTI_TYPE_INT16 -convert_verify -if cmp ${prefix}.0.i16.nii.gz ${prefix}.2.0.i16.nii.gz +if nii_cmp ${prefix}.0.i16.nii.gz ${prefix}.2.0.i16.nii.gz then echo "" else @@ -57,7 +74,7 @@ ${NT} -cbl -infile ${prefix}.0.i16.nii.gz \ ${NT} -copy_image -infile ${prefix}.1.f32.nii.gz \ -prefix ${prefix}.2.1.i16.nii.gz \ -convert2dtype NIFTI_TYPE_INT16 -convert_fail_choice warn -if cmp ${prefix}.0.i16.nii.gz ${prefix}.2.1.i16.nii.gz +if nii_cmp ${prefix}.0.i16.nii.gz ${prefix}.2.1.i16.nii.gz then echo "" else