Yalantis/uCrop · warning
load_analyze(): File
Error message
load_analyze(): File '%s' defines an image with zero dimensions.
What it means
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.
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.
Example fix
// before (blind load)
CImg<float> img; img.load_analyze("bad.hdr");
// after (validate header first)
unsigned char header[348]; std::FILE* f = std::fopen("bad.hdr","rb"); std::fread(header,1,348,f); std::fclose(f);
unsigned short dim0 = *(unsigned short*)(header + 40);
if (dim0 == 0) throw std::runtime_error("bad.hdr: dim[0]==0, invalid ANALYZE header");
img.load_analyze("bad.hdr"); Defensive patterns
Strategy: validation
Validate before calling
unsigned char h[348]; if (std::fread(h,1,348,f) != 348) fail(); if (*(unsigned short*)(h + 40) == 0) fail();
Type guard
bool analyzeHeaderHasDims(const unsigned char* header348) { return *(const unsigned short*)(header348 + 40) != 0; } Try / catch
try { img.load_analyze(path); } catch (CImgIOException& e) { /* handle unreadable file */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- load_analyze(): File
- load_bmp(): File size %lu for filename
- load_bmp(): Invalid offset
- load_bmp(): Malformed header in filename
- load_jpeg(): Error message returned by libjpeg
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/198366f41c7ad13c.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:58451
if (!file && nfile_header!=nfile) cimg::fclose(nfile_header);
if (endian) {
cimg::invert_endianness((short*)(header + 40),5);
cimg::invert_endianness((short*)(header + 70),1);
cimg::invert_endianness((short*)(header + 72),1);
cimg::invert_endianness((float*)(header + 76),4);
cimg::invert_endianness((float*)(header + 108),1);
cimg::invert_endianness((float*)(header + 112),1);
}
if (nfile_header==nfile) {
const unsigned int vox_offset = (unsigned int)*(float*)(header + 108);
std::fseek(nfile,vox_offset,SEEK_SET);
}
unsigned short *dim = (unsigned short*)(header + 40), dimx = 1, dimy = 1, dimz = 1, dimv = 1;
if (!dim[0])
cimg::warn(_cimg_instance
"load_analyze(): File '%s' defines an image with zero dimensions.",
cimg_instance,
filename?filename:"(FILE*)");
if (dim[0]>4)
cimg::warn(_cimg_instance
"load_analyze(): File '%s' defines an image with %u dimensions, reading only the 4 first.",
cimg_instance,
filename?filename:"(FILE*)",dim[0]);
if (dim[0]>=1) dimx = dim[1];
if (dim[0]>=2) dimy = dim[2];
if (dim[0]>=3) dimz = dim[3];
if (dim[0]>=4) dimv = dim[4];
float scalefactor = *(float*)(header + 112); if (scalefactor==0) scalefactor = 1;
const unsigned short datatype = *(unsigned short*)(header + 70);
if (voxel_size) {
const float *vsize = (float*)(header + 76);View on GitHub (pinned to f788b534b4)