Yalantis/uCrop · error · CImgArgumentException
load_medcon_external(): Specified filename is (null) or does
Error message
load_medcon_external(): Specified filename is (null) or does not exist.
What it means
load_medcon_external() loads a DICOM image by delegating to the external 'medcon' tool. Before doing anything, it validates the argument: if filename is null or cimg::is_file() says no such regular file exists, it throws this CImgArgumentException immediately.
Source
Thrown at ucrop/src/main/jni/CImg.h:59863
#else
load_pnm(filename_tmp);
#endif
std::remove(filename_tmp);
return *this;
}
//! Load image using ImageMagick's external tool 'convert' \newinstance.
static CImg<T> get_load_imagemagick_external(const char *const filename) {
return CImg<T>().load_imagemagick_external(filename);
}
//! Load image from a DICOM file, using Medcon's external tool 'medcon'.
/**
\param filename Filename, as a C-string.
**/
CImg<T>& load_medcon_external(const char *const filename) {
if (!filename || !cimg::is_file(filename))
throw CImgArgumentException(_cimg_instance
"load_medcon_external(): Specified filename is (null) or does not exist.",
cimg_instance);
CImg<charT> command(1024), filename_tmp(256), body(256);
do {
cimg_snprintf(filename_tmp,filename_tmp._width,"%s.hdr",cimg::filenamerand());
} while (cimg::path_exists(filename_tmp));
cimg_snprintf(command,command._width,"\"%s\" -w -c anlz -o \"%s\" -f \"%s\"",
cimg::medcon_path(),
CImg<charT>::string(filename_tmp)._system_strescape().data(),
CImg<charT>::string(filename)._system_strescape().data());
cimg::system(command,cimg::medcon_path());
cimg::split_filename(filename_tmp,body);
cimg_snprintf(command,command._width,"%s.hdr",body._data);
if (!cimg::path_exists(command)) {
cimg_snprintf(command,command._width,"m000-%s.hdr",body._data);
if (!cimg::path_exists(command)) {
throw CImgIOException(_cimg_instanceView on GitHub (pinned to f788b534b4)
Solutions
- Check the path with stat/access before calling: ensure the file exists and is a regular file.
- Print/log the exact absolute path being passed (realpath()) and fix the construction of the path.
- Verify the process working directory if using relative paths; switch to absolute paths.
- Fix the source of the path (config field, database record, user argument) so it is never null/empty.
- If DICOM loading is optional, guard the call and skip with a clear message instead of passing a bad path.
Example fix
// before
img.load_medcon_external(cfg.dicomPath); // may be null/missing
// after
if (!cfg.dicomPath || !cimg::is_file(cfg.dicomPath))
throw std::invalid_argument("DICOM file missing: " + std::string(cfg.dicomPath?cfg.dicomPath:"(null)"));
img.load_medcon_external(cfg.dicomPath); Defensive patterns
Strategy: validation
Validate before calling
if (!path || !cimg::is_file(path))
throw std::invalid_argument("DICOM path null or does not exist"); Type guard
bool isExistingFile(const char* p){ return p && cimg::is_file(p); } Try / catch
try { img.load_medcon_external(path); }
catch (CImgArgumentException& e) { log("bad DICOM path"); } Prevention
- Always resolve and validate paths before external loaders
- Use absolute paths
- Check case-sensitive extensions on Linux
- Validate config/DB fields that supply file paths
When it happens
Trigger: Calling CImg<T>::load_medcon_external(nullptr), or passing a path that does not exist, is a directory, or is a dangling symlink. Also reached when callers pass a path relative to a different working directory than the one the process runs in.
Common situations: Config or user input supplying an empty/missing DICOM path; filename built by string concatenation where an optional directory part was empty; working-directory mismatch between dev and deployment; typo in extension or case-sensitive filesystem differences.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- load_dcraw_external(): Specified filename is (null) or does
- cimg::fopen(): Specified file path is (null).
- cimg::fopen(): File '%s', specified mode is (null).
- cimg::fread(): Invalid reading request of %u %s%s from file
- cimg::fwrite(): Invalid writing request of %u %s%s from buff
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/887f0f9047050031.
Report an issue: GitHub.