Yalantis/uCrop · error · CImgArgumentException
cimg::load_network(): Specified URL is (null).
Error message
cimg::load_network(): Specified URL is (null).
What it means
cimg::load_network() downloads a file from a URL to a local path (via libcurl, wget, or curl). The library throws this CImgArgumentException when the url pointer itself is null, because no download can be started without an address. It is the first null-check guard in the function.
Source
Thrown at ucrop/src/main/jni/CImg.h:70061
return f_type;
}
//! Load file from network as a local temporary file.
/**
\param url URL of the filename, as a C-string.
\param[out] filename_local C-string containing the path to a local copy of \c filename.
\param timeout Maximum time (in seconds) authorized for downloading the file from the URL.
\param try_fallback When using libcurl, tells using system calls as fallbacks in case of libcurl failure.
\param referer Referer used, as a C-string.
\param user_agent User agent used, as a C-string.
\return Value of \c filename_local.
\note Use the \c libcurl library, or the external binaries \c wget or \c curl to perform the download.
**/
inline char *load_network(const char *const url, char *const filename_local,
const unsigned int timeout, const bool try_fallback,
const char *const referer, const char *const user_agent) {
if (!url)
throw CImgArgumentException("cimg::load_network(): Specified URL is (null).");
if (!filename_local)
throw CImgArgumentException("cimg::load_network(): Specified destination string is (null).");
if (!network_mode())
throw CImgIOException("cimg::load_network(): Loading files from network is disabled.");
const char *const __ext = cimg::split_filename(url), *const _ext = (*__ext && __ext>url)?__ext - 1:__ext;
CImg<char> ext = CImg<char>::string(_ext);
*filename_local = 0;
if (ext._width>16 || !cimg::strncasecmp(ext,"cgi",3)) *ext = 0;
else cimg::strwindows_reserved(ext);
do {
cimg_snprintf(filename_local,256,"%s%c%s%s",
cimg::temporary_path(),cimg_file_separator,cimg::filenamerand(),ext._data);
} while (cimg::path_exists(filename_local));
#ifdef cimg_use_curl
const unsigned int omode = cimg::exception_mode();
cimg::exception_mode(0);View on GitHub (pinned to f788b534b4)
Solutions
- Pass a valid, non-null URL string to load_network.
- Check the URL variable for null/empty before calling; fall back to a default URL or fail fast with a clear message.
- If the URL comes from config/JNI, validate at the boundary (non-empty, starts with http:// or https://).
- Catch CImgArgumentException around the call to convert it into a handled error path.
Example fix
// before img.load_network(url, localPath); // url may be NULL // after if (url && *url) img.load_network(url, localPath); else fprintf(stderr, "no URL configured for remote image");
Defensive patterns
Strategy: validation
Validate before calling
bool isValidUrl(const char *u) { return u && *u && (strncmp(u, "http://", 7) == 0 || strncmp(u, "https://", 8) == 0); } Type guard
bool nonEmptyString(const char *s) { return s != nullptr && *s != '\0'; } Try / catch
try { img.load_network(url, local, 30, true, 0, 0); } catch (const CImgArgumentException &e) { fprintf(stderr, "bad argument for load_network: %s", e.what()); } Prevention
- Check the URL for null/empty and http(s) scheme before any network load call
- Source URLs from validated config, not raw uninitialized pointers
- Reject missing config keys at startup instead of letting null propagate to the download call
When it happens
Trigger: Calling cimg::load_network(NULL, dest, ...) directly, or via CImg<T>::load_network/load with a filename that resolved to a null pointer (e.g. from an unset config value or a failed string conversion).
Common situations: Fetching remote image templates where the URL config key is missing; JNI code passing a null string from Java; refactored code where the URL variable was removed or conditionally assigned.
Related errors
- cimg::load_network(): Specified destination string is (null)
- 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/d75d75d493567aa5.
Report an issue: GitHub.