Yalantis/uCrop · error · CImgArgumentException
load_pdf_external(): Specified filename is (null).
Error message
load_pdf_external(): Specified filename is (null).
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:59907
cimg::split_filename(command,body);
cimg_snprintf(command,command._width,"%s.img",body._data);
std::remove(command);
return *this;
}
//! Load image from a DICOM file, using Medcon's external tool 'medcon' \newinstance.
static CImg<T> get_load_medcon_external(const char *const filename) {
return CImg<T>().load_medcon_external(filename);
}
//! Load image from a .pdf file.
/**
\param filename Filename, as a C-string.
\param resolution Image resolution.
**/
CImg<T>& load_pdf_external(const char *const filename, const unsigned int resolution=400) {
if (!filename)
throw CImgArgumentException(_cimg_instance
"load_pdf_external(): Specified filename is (null).",
cimg_instance);
CImg<charT> command(1024), filename_tmp(256);
const CImg<charT> s_filename = CImg<charT>::string(filename)._system_strescape();
#if cimg_OS==1
std::FILE *file = 0;
cimg_snprintf(command,command._width,"gs -q -dNOPAUSE -sDEVICE=ppmraw -o - -r%u \"%s\"",
resolution,s_filename.data());
file = popen(command,"r");
if (file) {
const unsigned int omode = cimg::exception_mode();
cimg::exception_mode(0);
try { load_pnm(file); } catch (...) {
pclose(file);
cimg::exception_mode(omode);
throw CImgIOException(_cimg_instance
"load_pdf_external(): Failed to load file '%s' with external command 'gs'.",
cimg_instance,View on GitHub (pinned to f788b534b4)
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.
Example fix
// before
img.load_pdf_external(path); // path may be NULL
// after
if (!path) throw std::invalid_argument("PDF path is null");
if (!cimg::is_file(path)) throw std::invalid_argument("PDF not found");
img.load_pdf_external(path); Defensive patterns
Strategy: type-guard
Validate before calling
if (!path) throw std::invalid_argument("PDF path is null");
if (!cimg::is_file(path)) throw std::invalid_argument("PDF file not found"); Type guard
bool validPdfPath(const char* p){ return p && cimg::is_file(p); } Try / catch
try { img.load_pdf_external(path, res); }
catch (CImgArgumentException& e) { log("null/invalid PDF path"); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- load_pdf_external(): Failed to load file '%s' with external
- load(): Specified filename is (null).
- load_ascii(): Specified filename is (null).
- load_dlm(): Specified filename is (null).
- load_bmp(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/df0f8247351ff2e2.
Report an issue: GitHub.