{"record":{"id":"198366f41c7ad13c","repo":"Yalantis/uCrop","slug":"load-analyze-file-s-defines-an-image-with-ze","errorCode":null,"errorMessage":"load_analyze(): File '%s' defines an image with zero dimensions.","messagePattern":"load_analyze\\(\\): File '(.+?)' defines an image with zero dimensions\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58451,"sourceCode":"\n      if (!file && nfile_header!=nfile) cimg::fclose(nfile_header);\n      if (endian) {\n        cimg::invert_endianness((short*)(header + 40),5);\n        cimg::invert_endianness((short*)(header + 70),1);\n        cimg::invert_endianness((short*)(header + 72),1);\n        cimg::invert_endianness((float*)(header + 76),4);\n        cimg::invert_endianness((float*)(header + 108),1);\n        cimg::invert_endianness((float*)(header + 112),1);\n      }\n\n      if (nfile_header==nfile) {\n        const unsigned int vox_offset = (unsigned int)*(float*)(header + 108);\n        std::fseek(nfile,vox_offset,SEEK_SET);\n      }\n\n      unsigned short *dim = (unsigned short*)(header + 40), dimx = 1, dimy = 1, dimz = 1, dimv = 1;\n      if (!dim[0])\n        cimg::warn(_cimg_instance\n                   \"load_analyze(): File '%s' defines an image with zero dimensions.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n\n      if (dim[0]>4)\n        cimg::warn(_cimg_instance\n                   \"load_analyze(): File '%s' defines an image with %u dimensions, reading only the 4 first.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\",dim[0]);\n\n      if (dim[0]>=1) dimx = dim[1];\n      if (dim[0]>=2) dimy = dim[2];\n      if (dim[0]>=3) dimz = dim[3];\n      if (dim[0]>=4) dimv = dim[4];\n      float scalefactor = *(float*)(header + 112); if (scalefactor==0) scalefactor = 1;\n      const unsigned short datatype = *(unsigned short*)(header + 70);\n      if (voxel_size) {\n        const float *vsize = (float*)(header + 76);","sourceCodeStart":58433,"sourceCodeEnd":58469,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58433-L58469","documentation":"load_analyze() reads the dim[] array of an ANALYZE 7.5 header; if dim[0] is 0 the file declares a zero-dimensional dataset. The library warns (cimg::warn, non-fatal) and proceeds with default dimensions 1x1x1x1, so the resulting image is almost certainly not the intended data.","triggerScenarios":"Loading an ANALYZE (.hdr/.img) file whose header byte at offset 40 (dim[0], number of dimensions) is 0, via CImg::load_analyze() or load() dispatching on extension.","commonSituations":"Corrupt or truncated header files; headers written by tools that leave dim[0]=0 for placeholders; byte-order/struct-offset mismatch when the header was hand-patched; loading a template header never filled in.","solutions":["Regenerate or repair the .hdr so dim[0] (and dim[1..dim[0]]) are set correctly (e.g. with fslchfiletype/Analyze tooling or a script writing the 348-byte header).","Verify endianness: ANALYZE headers have a sizeof_hdr magic (348); if bytes are swapped, dim[0] reads as garbage/0.","Convert the dataset to NIfTI-1 and load it with load_nii instead, if your CImg build supports it.","Sanity-check the file: dump bytes at header offset 40 to confirm dim[0] before blaming the loader."],"exampleFix":"// before (blind load)\nCImg<float> img; img.load_analyze(\"bad.hdr\");\n// after (validate header first)\nunsigned char header[348]; std::FILE* f = std::fopen(\"bad.hdr\",\"rb\"); std::fread(header,1,348,f); std::fclose(f);\nunsigned short dim0 = *(unsigned short*)(header + 40);\nif (dim0 == 0) throw std::runtime_error(\"bad.hdr: dim[0]==0, invalid ANALYZE header\");\nimg.load_analyze(\"bad.hdr\");","handlingStrategy":"validation","validationCode":"unsigned char h[348]; if (std::fread(h,1,348,f) != 348) fail();\nif (*(unsigned short*)(h + 40) == 0) fail();","typeGuard":"bool analyzeHeaderHasDims(const unsigned char* header348) { return *(const unsigned short*)(header348 + 40) != 0; }","tryCatchPattern":"try { img.load_analyze(path); } catch (CImgIOException& e) { /* handle unreadable file */ }","preventionTips":["Check dim[0] at header offset 40 before loading ANALYZE files.","Verify header endianness (sizeof_hdr == 348).","Convert legacy ANALYZE data to NIfTI when possible."],"tags":["analyze","hdr","image-loading","corrupt-file"],"backgroundTag":"value-out-of-range","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}