{"record":{"id":"7d0f7b457972c06b","repo":"Yalantis/uCrop","slug":"load-graphicsmagick-external-specified-filename","errorCode":null,"errorMessage":"load_graphicsmagick_external(): Specified filename is (null) or does not exist.","messagePattern":"load_graphicsmagick_external\\(\\): Specified filename is \\(null\\) or does not exist\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59626,"sourceCode":"        cimg_forX(*this,x) {\n          *(ptr_r++) = (T)*(ptrs++);\n          *(ptr_g++) = (T)*(ptrs++);\n          *(ptr_b++) = (T)*(ptrs++);\n          if (ptr_a) *(ptr_a++) = (T)*(ptrs++);\n        }\n      }\n      WebPFreeDecBuffer(&config.output);\n      return *this;\n#endif\n    }\n\n    //! Load image using GraphicsMagick's external tool 'gm'.\n    /**\n       \\param filename Filename, as a C-string.\n    **/\n    CImg<T>& load_graphicsmagick_external(const char *const filename) {\n      if (!filename || !cimg::is_file(filename))\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_graphicsmagick_external(): Specified filename is (null) or does not exist.\",\n                                    cimg_instance);\n      CImg<charT> command(1024), filename_tmp(256);\n      const CImg<charT> s_filename = CImg<charT>::string(filename)._system_strescape();\n#if cimg_OS==1\n      if (cimg::posix_searchpath(\"gm\")) {\n        cimg_snprintf(command,command._width,\"%s convert \\\"%s\\\" %s:-\",\n                      cimg::graphicsmagick_path(),\n                      s_filename.data(),\n#ifdef cimg_use_png\n                      \"png\"\n#else\n                      \"pnm\"\n#endif\n                      );\n        std::FILE *file = popen(command,\"r\");\n        if (file) {\n          const unsigned int omode = cimg::exception_mode();","sourceCodeStart":59608,"sourceCodeEnd":59644,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59608-L59644","documentation":"load_graphicsmagick_external() first validates that the filename argument is non-null and points to an existing regular file via cimg::is_file(); if not, it throws CImgArgumentException before any external 'gm' command is run. This is an argument precondition, not a decode failure.","triggerScenarios":"Calling load_graphicsmagick_external(NULL) or with a path that does not exist, is a directory, or is a dangling symlink.","commonSituations":"Path built from a config value that was never resolved; working-directory assumptions breaking after deployment; passing a URL or in-memory buffer name instead of a real filesystem path; typo'd relative paths.","solutions":["Check the path with a filesystem stat (or cimg::is_file) before calling and handle the missing-file case","Pass an absolute path resolved against a known base directory","Fix the code that produces the filename (config, env, user input) so it yields an existing file","If the image is not on disk, write it to a temp file first, then call load_graphicsmagick_external() on it"],"exampleFix":"// before\nimg.load_graphicsmagick_external(fname); // fname may be NULL / missing\n// after\nif (fname && cimg::is_file(fname)) {\n  img.load_graphicsmagick_external(fname);\n} else {\n  throw std::invalid_argument(\"input file does not exist\");\n}","handlingStrategy":"validation","validationCode":"if (!filename || !cimg::is_file(filename)) {\n  throw std::invalid_argument(std::string(\"input file missing: \") + (filename ? filename : \"(null)\"));\n}\nimg.load_graphicsmagick_external(filename);","typeGuard":"bool loadable_file(const char* f) { return f != nullptr && cimg::is_file(f); }","tryCatchPattern":"try {\n  img.load_graphicsmagick_external(filename);\n} catch (CImgArgumentException& e) {\n  log_error(\"bad path for gm loader: \", e.what());\n}","preventionTips":["Always stat paths (cimg::is_file) before external-tool loaders","Use absolute paths built from a known base directory","Initialize filename variables; never pass possibly-NULL pointers","Unit-test path resolution with missing-file cases"],"tags":["cimg","graphicsmagick","argument-validation","file-not-found"],"backgroundTag":"null-argument","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"}