{"record":{"id":"df0f8247351ff2e2","repo":"Yalantis/uCrop","slug":"load-pdf-external-specified-filename-is-null","errorCode":null,"errorMessage":"load_pdf_external(): Specified filename is (null).","messagePattern":"load_pdf_external\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59907,"sourceCode":"      cimg::split_filename(command,body);\n      cimg_snprintf(command,command._width,\"%s.img\",body._data);\n      std::remove(command);\n      return *this;\n    }\n\n    //! Load image from a DICOM file, using Medcon's external tool 'medcon' \\newinstance.\n    static CImg<T> get_load_medcon_external(const char *const filename) {\n      return CImg<T>().load_medcon_external(filename);\n    }\n\n    //! Load image from a .pdf file.\n    /**\n       \\param filename Filename, as a C-string.\n       \\param resolution Image resolution.\n    **/\n    CImg<T>& load_pdf_external(const char *const filename, const unsigned int resolution=400) {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_pdf_external(): Specified filename is (null).\",\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      std::FILE *file = 0;\n      cimg_snprintf(command,command._width,\"gs -q -dNOPAUSE -sDEVICE=ppmraw -o - -r%u \\\"%s\\\"\",\n                    resolution,s_filename.data());\n      file = popen(command,\"r\");\n      if (file) {\n        const unsigned int omode = cimg::exception_mode();\n        cimg::exception_mode(0);\n        try { load_pnm(file); } catch (...) {\n          pclose(file);\n          cimg::exception_mode(omode);\n          throw CImgIOException(_cimg_instance\n                                \"load_pdf_external(): Failed to load file '%s' with external command 'gs'.\",\n                                cimg_instance,","sourceCodeStart":59889,"sourceCodeEnd":59925,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59889-L59925","documentation":"load_pdf_external() renders a PDF page via external ghostscript ('gs'). It first validates its argument: if filename is null it throws this CImgArgumentException. Unlike some sibling loaders it only checks for null, not for file existence.","triggerScenarios":"Calling CImg<T>::load_pdf_external(nullptr) or load_pdf_external(NULL, resolution); typically when a path variable was never assigned, an optional config value is absent, or an upstream API returned null for the document path.","commonSituations":"Null returned by getenv()/config lookup passed straight through; caller of a wrapper function forwarding an unset filename; strings from JSON deserialization where the key was missing.","solutions":["Null-check the filename (or assert it) before calling load_pdf_external.","Resolve the source of the null path (config key, env var, DB field) and provide a default or explicit failure earlier.","Also verify the file exists yourself, since this function does not check existence: cimg::is_file(path).","Refuse to proceed with a clear application-level error instead of passing null into the loader."],"exampleFix":"// before\nimg.load_pdf_external(path); // path may be NULL\n// after\nif (!path) throw std::invalid_argument(\"PDF path is null\");\nif (!cimg::is_file(path)) throw std::invalid_argument(\"PDF not found\");\nimg.load_pdf_external(path);","handlingStrategy":"type-guard","validationCode":"if (!path) throw std::invalid_argument(\"PDF path is null\");\nif (!cimg::is_file(path)) throw std::invalid_argument(\"PDF file not found\");","typeGuard":"bool validPdfPath(const char* p){ return p && cimg::is_file(p); }","tryCatchPattern":"try { img.load_pdf_external(path, res); }\ncatch (CImgArgumentException& e) { log(\"null/invalid PDF path\"); }","preventionTips":["Null-check every path obtained from getenv/config/DB before loader calls","Never pass through unassigned pointers","Validate file existence yourself — this function only checks for null","Fail early with application-specific errors"],"tags":["pdf","ghostscript","null-argument","cimg"],"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"}