{"record":{"id":"5bfcaa3014526da4","repo":"Yalantis/uCrop","slug":"cimg-s-load-inr-invalid-dimensions-d-d-d","errorCode":null,"errorMessage":"CImg<%s>::load_inr(): Invalid dimensions (%d,%d,%d,%d) defined in header.","messagePattern":"CImg<(.+?)>::load_inr\\(\\): Invalid dimensions \\((.+?),(.+?),(.+?),(.+?)\\) defined in header\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58681,"sourceCode":"        if (cimg_sscanf(item,\" CPU%*[ =]%s\",tmp1._data)) out[7] = cimg::strncasecmp(tmp1,\"sun\",3)?0:1;\n        switch (cimg_sscanf(item,\" TYPE%*[ =]%s %s\",tmp1._data,tmp2._data)) {\n        case 0 : break;\n        case 2 :\n          out[5] = cimg::strncasecmp(tmp1,\"unsigned\",8)?1:0;\n          std::strncpy(tmp1,tmp2,tmp1._width - 1); // Fallthrough\n        case 1 :\n          if (!cimg::strncasecmp(tmp1,\"int\",3) || !cimg::strncasecmp(tmp1,\"fixed\",5))  out[4] = 0;\n          if (!cimg::strncasecmp(tmp1,\"float\",5) || !cimg::strncasecmp(tmp1,\"double\",6)) out[4] = 1;\n          if (!cimg::strncasecmp(tmp1,\"packed\",6)) out[4] = 2;\n          if (out[4]>=0) break; // Fallthrough\n        default :\n          throw CImgIOException(\"CImg<%s>::load_inr(): Invalid pixel type '%s' defined in header.\",\n                                pixel_type(),\n                                tmp2._data);\n        }\n      }\n      if (out[0]<0 || out[1]<0 || out[2]<0 || out[3]<0)\n        throw CImgIOException(\"CImg<%s>::load_inr(): Invalid dimensions (%d,%d,%d,%d) defined in header.\",\n                              pixel_type(),\n                              out[0],out[1],out[2],out[3]);\n      if (out[4]<0 || out[5]<0)\n        throw CImgIOException(\"CImg<%s>::load_inr(): Incomplete pixel type defined in header.\",\n                              pixel_type());\n      if (out[6]<0)\n        throw CImgIOException(\"CImg<%s>::load_inr(): Incomplete PIXSIZE field defined in header.\",\n                              pixel_type());\n      if (out[7]<0)\n        throw CImgIOException(\"CImg<%s>::load_inr(): Big/Little Endian coding type undefined in header.\",\n                              pixel_type());\n    }\n\n    CImg<T>& _load_inr(std::FILE *const file, const char *const filename, float *const voxel_size) {\n#define _cimg_load_inr_case(Tf,sign,pixsize,Ts) \\\n     if (!loaded && fopt[6]==pixsize && fopt[4]==Tf && fopt[5]==sign) { \\\n        Ts *xval, *const val = new Ts[(size_t)fopt[0]*fopt[3]]; \\\n        cimg_forYZ(*this,y,z) { \\","sourceCodeStart":58663,"sourceCodeEnd":58699,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58663-L58699","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before (header)\nXDIM=-1\nYDIM=256\n# after\nXDIM=256\nYDIM=256\nZDIM=128\nVDIM=1","handlingStrategy":"validation","validationCode":"bool inrDimsValid(int x, int y, int z, int v) {\n  return x > 0 && y > 0 && z > 0 && v > 0;\n}\n// parse header text first, then call before load_inr()","typeGuard":"bool nonNegativeDims(const int out[4]) { return out[0] >= 0 && out[1] >= 0 && out[2] >= 0 && out[3] >= 0; }","tryCatchPattern":"try { img.load_inr(path); }\ncatch (CImgIOException& e) { fprintf(stderr, \"INR header dims invalid — check XDIM/YDIM/ZDIM/VDIM lines\\n\"); }","preventionTips":["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."],"tags":["cimg","dimensions","inrimage","header"],"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-14T05:17:10.506Z"}