{"record":{"id":"baae18747ae98d95","repo":"Yalantis/uCrop","slug":"load-ascii-invalid-ascii-header-in-file-s-i","errorCode":null,"errorMessage":"load_ascii(): Invalid ascii header in file '%s', image dimensions are set to (%u,%u,%u,%u).","messagePattern":"load_ascii\\(\\): Invalid ascii header in file '(.+?)', image dimensions are set to \\(%u,%u,%u,%u\\)\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":56666,"sourceCode":"    static CImg<T> get_load_ascii(std::FILE *const file) {\n      return CImg<T>().load_ascii(file);\n    }\n\n    CImg<T>& _load_ascii(std::FILE *const file, const char *const filename) {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_ascii(): Specified filename is (null).\",\n                                    cimg_instance);\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"rb\");\n      CImg<charT> line(256); *line = 0;\n      int err = std::fscanf(nfile,\"%255[^\\n]\",line._data);\n      unsigned int dx = 0, dy = 1, dz = 1, dc = 1;\n      cimg_sscanf(line,\"%u%*c%u%*c%u%*c%u\",&dx,&dy,&dz,&dc);\n      err = std::fscanf(nfile,\"%*[^0-9.eEinfa+-]\");\n      if (!dx || !dy || !dz || !dc) {\n        if (!file) cimg::fclose(nfile);\n        throw CImgIOException(_cimg_instance\n                              \"load_ascii(): Invalid ascii header in file '%s', image dimensions are set \"\n                              \"to (%u,%u,%u,%u).\",\n                              cimg_instance,\n                              filename?filename:\"(FILE*)\",dx,dy,dz,dc);\n      }\n      assign(dx,dy,dz,dc);\n      const ulongT siz = size();\n      ulongT off = 0;\n      double val;\n      T *ptr = _data;\n      for (err = 1, off = 0; off<siz && err==1; ++off) {\n        err = std::fscanf(nfile,\"%lf%*[^0-9.eEinfa+-]\",&val);\n        *(ptr++) = (T)val;\n      }\n      if (err!=1)\n        cimg::warn(_cimg_instance\n                   \"load_ascii(): Only %lu/%lu values read from file '%s'.\",\n                   cimg_instance,","sourceCodeStart":56648,"sourceCodeEnd":56684,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L56648-L56684","documentation":"load_ascii() read the first line expecting four unsigned integers (width,height,depth,spectrum); if any parsed dimension is 0 the header is rejected with CImgIOException. This catches files that are not valid CImg ASCII dumps.","triggerScenarios":"Pointing load_ascii() at a file whose first line is not 'dx dy dz dc' integers — e.g. an empty file, a PNG mislabeled as .cimg, or a manually edited ascii dump where a dimension became 0.","commonSituations":"Loading wrong file type (binary or foreign format) with the ASCII loader; truncated downloads whose header line is missing; hand-written data files with zero dimensions.","solutions":["Verify the file starts with a line of four positive integers (e.g. '256 256 1 3').","Use the correct loader for the actual file type (load_png/load_bmp/load_dlm).","Regenerate or repair the ASCII dump ensuring nonzero dx,dy,dz,dc.","Open the file and check it is non-empty before calling load_ascii."],"exampleFix":"// before\nimg.load_ascii(path); // first line '0 0 0 0'\n// after\nstd::ifstream in(path);\nunsigned dx,dy,dz,dc; in>>dx>>dy>>dz>>dc;\nif (dx&&dy&&dz&&dc) img.load_ascii(path);\nelse throw std::runtime_error(\"bad cimg ascii header\");","handlingStrategy":"validation","validationCode":"bool validCimgAsciiHeader(const char* p){ std::ifstream in(p); unsigned dx,dy,dz,dc; return static_cast<bool>(in>>dx>>dy>>dz>>dc) && dx&&dy&&dz&&dc; }","typeGuard":null,"tryCatchPattern":"try { img.load_ascii(path); } catch (cimg_library::CImgIOException& e) { /* bad header: not a cimg ascii dump */ }","preventionTips":["Only call load_ascii on files written by CImg save_ascii","Peek at the first line to confirm four positive integers","Don't rename foreign files to .cimg and expect them to load"],"tags":["cimg","ascii","file-format","validation"],"backgroundTag":"schema-validation-failed","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"}