{"record":{"id":"3d8b278a83fcc6ba","repo":"Yalantis/uCrop","slug":"load-raw-specified-filename-is-null","errorCode":null,"errorMessage":"load_raw(): Specified filename is (null).","messagePattern":"load_raw\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59089,"sourceCode":"      return _load_raw(file,0,size_x,size_y,size_z,size_c,is_multiplexed,invert_endianness,offset);\n    }\n\n    //! Load image from a raw binary file \\newinstance.\n    static CImg<T> get_load_raw(std::FILE *const file,\n                                const unsigned int size_x=0, const unsigned int size_y=1,\n                                const unsigned int size_z=1, const unsigned int size_c=1,\n                                const bool is_multiplexed=false, const bool invert_endianness=false,\n                                const ulongT offset=0) {\n      return CImg<T>().load_raw(file,size_x,size_y,size_z,size_c,is_multiplexed,invert_endianness,offset);\n    }\n\n    CImg<T>& _load_raw(std::FILE *const file, const char *const filename,\n                       const unsigned int size_x, const unsigned int size_y,\n                       const unsigned int size_z, const unsigned int size_c,\n                       const bool is_multiplexed, const bool invert_endianness,\n                       const ulongT offset) {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_raw(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (cimg::is_directory(filename))\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_raw(): Specified filename '%s' is a directory.\",\n                                    cimg_instance,filename);\n      const bool is_bool = pixel_type()==cimg::type<bool>::string();\n      ulongT siz = (ulongT)size_x*size_y*size_z*size_c;\n      unsigned int\n        _size_x = size_x,\n        _size_y = size_y,\n        _size_z = size_z,\n        _size_c = size_c;\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"rb\");\n      if (!siz) { // Retrieve file size\n        const longT fpos = cimg::ftell(nfile);\n        if (fpos<0) throw CImgArgumentException(_cimg_instance\n                                                \"load_raw(): Cannot determine size of input file '%s'.\",","sourceCodeStart":59071,"sourceCodeEnd":59107,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59071-L59107","documentation":"CImg's raw loader _load_raw() reads uncompressed pixel data of given dimensions from a FILE* or a named file. It throws CImgArgumentException when both file and filename are null, since there is nothing to read from. This guard runs before the directory check and any I/O.","triggerScenarios":"img.load_raw(NULL,...) with no FILE*; a null path from an unset env var or failed lookup; generic wrapper code forwarding null through to the loader.","commonSituations":"Missing config/env values for raw data paths; wrappers around load_raw that don't validate arguments; pipelines where an earlier step failed silently and produced a null path.","solutions":["Check filename non-null (and non-empty) before calling load_raw","Fix the upstream producer of the path (env var, config, previous pipeline step)","If a FILE* is intended, ensure fopen succeeded before passing it","Also verify the path is a file, not a directory (the next check after this one)"],"exampleFix":"// before\nimg.load_raw(path, dims...);\n// after\nif (!path || !*path) throw std::invalid_argument(\"raw file path required\");\nstruct stat st;\nif (stat(path, &st) != 0 || S_ISDIR(st.st_mode)) throw std::invalid_argument(\"not a file\");\nimg.load_raw(path, dims...);","handlingStrategy":"validation","validationCode":"if (!filename || !*filename) throw std::invalid_argument(\"raw file path required\");\nstruct stat st;\nif (stat(filename,&st)!=0) throw std::runtime_error(\"raw file does not exist\");\nif (S_ISDIR(st.st_mode)) throw std::invalid_argument(\"path is a directory\");","typeGuard":"bool is_loadable_file(const char *p) {\n  if (!p || !*p) return false;\n  struct stat st; return stat(p,&st)==0 && S_ISREG(st.st_mode);\n}","tryCatchPattern":"try { img.load_raw(path, dims...); } catch (const cimg_library::CImgArgumentException &e) { /* null path or directory */ log(e.what()); }","preventionTips":["Validate path is non-null, non-empty, and a regular file before load_raw","Check raw-dimensions math against actual file size to avoid downstream read errors","Fail loudly in pipeline steps that produce paths so null never propagates to loaders"],"tags":["cimg","image-loading","raw","null-argument"],"backgroundTag":"null-argument","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}