Yalantis/uCrop · error · CImgArgumentException
cimg::ftype(): Specified filename is (null).
Error message
cimg::ftype(): Specified filename is (null).
What it means
cimg::ftype() guesses the image file format from a FILE* or a filename. The library throws this CImgArgumentException when both the file handle and the filename pointer are null, since with neither input there is nothing whose format can be guessed. It is an argument-validation guard at the very top of the function.
Source
Thrown at ucrop/src/main/jni/CImg.h:69973
}
closedir(dir);
#endif
// Sort resulting list by lexicographic order.
if (res._width>=2) std::qsort(res._data,res._width,sizeof(CImg<char>),_sort_files);
return res;
}
//! Try to guess format from an image file.
/**
\param file Input file (can be \c 0 if \c filename is set).
\param filename Filename, as a C-string (can be \c 0 if \c file is set).
\return C-string containing the guessed file format, or \c 0 if nothing has been guessed.
**/
inline const char *ftype(std::FILE *const file, const char *const filename) {
if (!file && !filename)
throw CImgArgumentException("cimg::ftype(): Specified filename is (null).");
static const char
*const _bmp = "bmp",
*const _cr2 = "cr2",
*const _dcm = "dcm",
*const _gif = "gif",
*const _inr = "inr",
*const _jpg = "jpg",
*const _off = "off",
*const _pan = "pan",
*const _pfm = "pfm",
*const _png = "png",
*const _pnm = "pnm",
*const _tif = "tif",
*const _webp = "webp",
*const _jxl = "jxl";
const char *f_type = 0;
CImg<char> header;View on GitHub (pinned to f788b534b4)
Solutions
- Ensure a non-null filename or FILE* is passed to ftype (or to the CImg load call that reaches it).
- Validate the input path in your own code before invoking CImg load functions; reject empty strings early.
- If the path comes from Java via JNI, check for null/empty jstring before converting to a C string.
- Catch CImgArgumentException around the load call and surface a user-facing 'invalid file path' message instead of crashing.
Example fix
// before
CImg<unsigned char> img(uriPath.c_str()); // uriPath may be empty -> c_str() yields "", unresolved path leads to null
// after
if (uriPath.empty()) throw std::invalid_argument("image path is empty");
CImg<unsigned char> img(uriPath.c_str()); Defensive patterns
Strategy: validation
Validate before calling
bool canGuessFormat(const char *file_or_name) { return file_or_name != nullptr && *file_or_name != '\0'; }
if (!canGuessFormat(path)) { /* fail fast: no file to inspect */ } Type guard
bool hasValidPath(const char *p) { return p != nullptr && *p != '\0'; } Try / catch
try { img.load(path); } catch (const CImgArgumentException &e) { fprintf(stderr, "invalid file argument: %s", e.what()); } Prevention
- Never pass the result of an empty std::string's c_str() assuming it is usable — check emptiness first
- Validate JNI jstrings for null before GetStringUTFChars conversion
- Validate the image path at the boundary (UI/config layer) before calling CImg
- Wrap CImg load calls in a helper that centralizes null/empty checks
When it happens
Trigger: Calling cimg::ftype(NULL, NULL), or indirectly calling a CImg load/constructor path (e.g. CImg<T>(filename) or load_other) that passes through ftype after the filename failed to resolve (e.g. a null string from an unset variable).
Common situations: Android NDK/JNI code (uCrop bundles CImg) passing a null path from Java because the app never set the image URI; a std::string converted with .c_str() from an empty/failed lookup; refactorings that drop the filename argument before the call.
Related errors
- save_pandore(): Specified filename is (null).
- load_parrec(): Specified filename is (null).
- 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
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/8c3d920e93b66896.
Report an issue: GitHub.