{"record":{"id":"fef904eaca2e3d70","repo":"Yalantis/uCrop","slug":"load-cimg-invalid-specified-size-u-u-u-u-fef904","errorCode":null,"errorMessage":"load_cimg(): Invalid specified size (%u,%u,%u,%u) of image %u in file '%s'","messagePattern":"load_cimg\\(\\): Invalid specified size \\(%u,%u,%u,%u\\) of image %u in file '(.+?)'","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":66902,"sourceCode":"                                     const unsigned int z1, const unsigned int c1) {\n      return CImgList<T>().load_cimg(file,n0,n1,x0,y0,z0,c0,x1,y1,z1,c1);\n    }\n\n    CImgList<T>& _load_cimg(std::FILE *const file, const char *const filename,\n                            const unsigned int n0, const unsigned int n1,\n                            const unsigned int x0, const unsigned int y0,\n                            const unsigned int z0, const unsigned int c0,\n                            const unsigned int x1, const unsigned int y1,\n                            const unsigned int z1, const unsigned int c1) {\n#define _cimg_load_cimg_case2(Ts1,Ts2,Ts3,Tss) \\\n      if (!loaded && ((Ts1 && !cimg::strcasecmp(Ts1,str_pixeltype)) || \\\n                      (Ts2 && !cimg::strcasecmp(Ts2,str_pixeltype)) || \\\n                      (Ts3 && !cimg::strcasecmp(Ts3,str_pixeltype)))) { \\\n        for (unsigned int l = 0; l<=nn1; ++l) { \\\n          j = 0; while ((i=std::fgetc(nfile))!='\\n' && i>=0) tmp[j++] = (char)i; tmp[j] = 0; \\\n          W = H = D = C = 0; \\\n          if (cimg_sscanf(tmp,\"%u %u %u %u\",&W,&H,&D,&C)!=4) \\\n            throw CImgIOException(_cimglist_instance \\\n                                  \"load_cimg(): Invalid specified size (%u,%u,%u,%u) of image %u in file '%s'\", \\\n                                  cimglist_instance, \\\n                                  W,H,D,C,l,filename?filename:\"(FILE*)\"); \\\n          if (W*H*D*C>0) { \\\n            if (l<nn0 || nx0>=W || ny0>=H || nz0>=D || nc0>=C) cimg::fseek(nfile,W*H*D*C*sizeof(Tss),SEEK_CUR); \\\n            else { \\\n              const unsigned int \\\n                _nx1 = nx1==~0U?W - 1:nx1, \\\n                _ny1 = ny1==~0U?H - 1:ny1, \\\n                _nz1 = nz1==~0U?D - 1:nz1, \\\n                _nc1 = nc1==~0U?C - 1:nc1; \\\n              if (_nx1>=W || _ny1>=H || _nz1>=D || _nc1>=C) \\\n                throw CImgArgumentException(_cimglist_instance \\\n                                            \"load_cimg(): Invalid specified coordinates \" \\\n                                            \"[%u](%u,%u,%u,%u) -> [%u](%u,%u,%u,%u) \" \\\n                                            \"because image [%u] in file '%s' has size (%u,%u,%u,%u).\", \\\n                                            cimglist_instance, \\\n                                            n0,x0,y0,z0,c0,n1,x1,y1,z1,c1,l,filename?filename:\"(FILE*)\",W,H,D,C); \\","sourceCodeStart":66884,"sourceCodeEnd":66920,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L66884-L66920","documentation":"In the region-of-interest overload CImgList::load_cimg(filename,n0,...,c1), each image's header line must parse as exactly four unsigned dimensions '%u %u %u %u'; otherwise this error is thrown (CImg.h:66902). Same corruption/truncation cause as the non-ROI variant, but no compressed-size field is expected.","triggerScenarios":"Calling load_cimg(file, n0,n1, x0,x1, y0,y1, z0,z1, c0,c1) on a .cimg file whose per-image header has missing or non-numeric dimension fields (sscanf != 4).","commonSituations":"Truncated downloads; concatenated partial .cimg files; wrong file passed while intending another; header lines altered by text-mode transfer.","solutions":["Re-obtain an intact .cimg file and verify header lines look like 'W H D C'.","Confirm the file you opened is the CImg-format dataset, not another format.","Hexdump the first lines and repair or regenerate the header."],"exampleFix":"// before\nimgs.load_cimg(path, 0,1, 0,63, 0,63, 0,0, 0,2); // throws: truncated header\n\n// after\nif (verifyCimgHeaders(path)) // check each line parses as 4 uints\n  imgs.load_cimg(path, 0,1, 0,63, 0,63, 0,0, 0,2);\nelse\n  reDownloadDataset(path);","handlingStrategy":"validation","validationCode":"bool roiHeaderParses(const char* path) {\n  std::FILE* f = std::fopen(path, \"rb\"); if (!f) return false;\n  char line[256] = {0};\n  bool ok = std::fgets(line, sizeof line, f) != nullptr; // list header\n  unsigned N, W, H, D, C;\n  if (ok) std::sscanf(line, \"%u\", &N);\n  for (unsigned l = 0; ok && l < N; ++l) {\n    if (!std::fgets(line, sizeof line, f)) { ok = false; break; }\n    ok = std::sscanf(line, \"%u %u %u %u\", &W, &H, &D, &C) == 4;\n  }\n  std::fclose(f);\n  return ok;\n}","typeGuard":null,"tryCatchPattern":"try {\n  imgs.load_cimg(path, n0,n1, x0,x1, y0,y1, z0,z1, c0,c1);\n} catch (cimg_library::CImgIOException& e) {\n  logError(\"bad .cimg size header for ROI load: %s\", e.what());\n  reExportDataset(path);\n}","preventionTips":["Verify each per-image header line parses as 4 integers before ROI loads","Checksum datasets after download","Avoid opening partially written files (check writer finished marker)","Keep .cimg handling in binary-safe I/O only"],"tags":["cimg","cpp","file-corruption","roi","parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}