Yalantis/uCrop · error · CImgIOException
CImg<%s>::load_inr(): Invalid dimensions (%d,%d,%d,%d) defin
Error message
CImg<%s>::load_inr(): Invalid dimensions (%d,%d,%d,%d) defined in header.
What it means
After parsing XDIM/YDIM/ZDIM/VDIM from the INR header, _load_inr_header() checks that all four dimension fields are non-negative; out[0..3] stay -1 for any field never set. Negative or missing dimensions make the image geometry invalid, so this exception is thrown with the four parsed values.
Source
Thrown at ucrop/src/main/jni/CImg.h:58681
if (cimg_sscanf(item," CPU%*[ =]%s",tmp1._data)) out[7] = cimg::strncasecmp(tmp1,"sun",3)?0:1;
switch (cimg_sscanf(item," TYPE%*[ =]%s %s",tmp1._data,tmp2._data)) {
case 0 : break;
case 2 :
out[5] = cimg::strncasecmp(tmp1,"unsigned",8)?1:0;
std::strncpy(tmp1,tmp2,tmp1._width - 1); // Fallthrough
case 1 :
if (!cimg::strncasecmp(tmp1,"int",3) || !cimg::strncasecmp(tmp1,"fixed",5)) out[4] = 0;
if (!cimg::strncasecmp(tmp1,"float",5) || !cimg::strncasecmp(tmp1,"double",6)) out[4] = 1;
if (!cimg::strncasecmp(tmp1,"packed",6)) out[4] = 2;
if (out[4]>=0) break; // Fallthrough
default :
throw CImgIOException("CImg<%s>::load_inr(): Invalid pixel type '%s' defined in header.",
pixel_type(),
tmp2._data);
}
}
if (out[0]<0 || out[1]<0 || out[2]<0 || out[3]<0)
throw CImgIOException("CImg<%s>::load_inr(): Invalid dimensions (%d,%d,%d,%d) defined in header.",
pixel_type(),
out[0],out[1],out[2],out[3]);
if (out[4]<0 || out[5]<0)
throw CImgIOException("CImg<%s>::load_inr(): Incomplete pixel type defined in header.",
pixel_type());
if (out[6]<0)
throw CImgIOException("CImg<%s>::load_inr(): Incomplete PIXSIZE field defined in header.",
pixel_type());
if (out[7]<0)
throw CImgIOException("CImg<%s>::load_inr(): Big/Little Endian coding type undefined in header.",
pixel_type());
}
CImg<T>& _load_inr(std::FILE *const file, const char *const filename, float *const voxel_size) {
#define _cimg_load_inr_case(Tf,sign,pixsize,Ts) \
if (!loaded && fopt[6]==pixsize && fopt[4]==Tf && fopt[5]==sign) { \
Ts *xval, *const val = new Ts[(size_t)fopt[0]*fopt[3]]; \
cimg_forYZ(*this,y,z) { \View on GitHub (pinned to f788b534b4)
Solutions
- Open the INR header and ensure XDIM, YDIM, ZDIM, VDIM lines exist with positive integers (VDIM>=1).
- Re-export the file with a standard INR writer to regenerate a well-formed header.
- If you generate headers programmatically, validate dimensions > 0 before writing '##}'.
- Check that earlier header fields (TYPE/PIXSIZE) parse correctly — a malformed switch can cascade.
- Catch CImgIOException and log the four dimension values to identify which field is bad.
Example fix
# before (header) XDIM=-1 YDIM=256 # after XDIM=256 YDIM=256 ZDIM=128 VDIM=1
Defensive patterns
Strategy: validation
Validate before calling
bool inrDimsValid(int x, int y, int z, int v) {
return x > 0 && y > 0 && z > 0 && v > 0;
}
// parse header text first, then call before load_inr() Type guard
bool nonNegativeDims(const int out[4]) { return out[0] >= 0 && out[1] >= 0 && out[2] >= 0 && out[3] >= 0; } Try / catch
try { img.load_inr(path); }
catch (CImgIOException& e) { fprintf(stderr, "INR header dims invalid — check XDIM/YDIM/ZDIM/VDIM lines\n"); } Prevention
- Never write placeholder dimensions (-1) into generated headers.
- Assert all four dimension lines exist with positive values before '##}'.
- Diff generated headers against a known-good template.
- Log the parsed dims from the exception context for repair.
When it happens
Trigger: Header missing XDIM/YDIM/ZDIM/VDIM lines, or containing negative values; fscanf patterns (' XDIM%*[^0-9]%d') fail to match (e.g. 'XDIM:abc'), leaving defaults -1; raised from load_inr()/load() on .inr files.
Common situations: Manually edited or template-generated headers with placeholder dimensions like XDIM=-1; truncated header write that dropped dimension lines; a TYPE parse failure earlier causing fallthrough into the dimension check path.
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
- CImg<%s>::load_inr(): Invalid pixel type '%s' defined in hea
- CImg<%s>::load_inr(): Incomplete pixel type defined in heade
- CImg<%s>::load_inr(): Incomplete PIXSIZE field defined in he
- CImg<%s>::load_inr(): Big/Little Endian coding type undefine
- det(): Instance is not a square matrix.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/5bfcaa3014526da4.
Report an issue: GitHub.