From 09adee5bf3004af9e8e3f7f204544be8c76933a3 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 fails on systems whose zlib is zlib-ng 1.3.1. 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. zlib-ng, which Arch, CachyOS, and a growing number of distributions ship in place of stock zlib, 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. The i16 -> f32 -> i16 comparison now also fails the test on a mismatch; it only printed a message before. 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. --- .../cmake_testscripts/c22_copy_image.sh | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 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..1f1d94d7 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,17 @@ DATA=$2 OUT_DATA=$(dirname ${DATA}) #Need to write to separate directory cd ${OUT_DATA} +# gzip output differs across zlib implementations, so compare decompressed content. +nii_cmp() { + if [ "${1##*.}" = "gz" ]; then + rc=0 + gzip -dc "$1" > "$1.raw" && gzip -dc "$2" > "$2.raw" && cmp "$1.raw" "$2.raw" || rc=1 + rm -f "$1.raw" "$2.raw" + return $rc + 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,11 +53,11 @@ ${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 -echo "** not a binary match: ${prefix}.0.i16.nii.gz ${prefix}.2.0.i16.nii.gz" +echo "** decompressed content differs: ${prefix}.0.i16.nii.gz ${prefix}.2.0.i16.nii.gz" exit 1 fi @@ -57,10 +68,11 @@ ${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 -echo "** not a binary match: ${prefix}.0.i16.nii.gz ${prefix}.2.1.i16.nii.gz" +echo "** decompressed content differs: ${prefix}.0.i16.nii.gz ${prefix}.2.1.i16.nii.gz" +exit 1 fi