{"record":{"id":"9404a03e334166d6","repo":"Yalantis/uCrop","slug":"cimg-load-network-failed-to-load-file-s-wit-9404a0","errorCode":null,"errorMessage":"cimg::load_network(): Failed to load file '%s' with external commands 'wget', 'curl', or 'powershell'.","messagePattern":"cimg::load_network\\(\\): Failed to load file '(.+?)' with external commands 'wget', 'curl', or 'powershell'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":70157,"sourceCode":"        cimg::system(command,cimg::powershell_path());\n      }\n#endif\n\n      if (cimg::fsize(filename_local)<=0) { // Try with 'wget' otherwise\n        if (timeout) cimg_snprintf(s_timeout.assign(64),64,\"-T %u \",timeout);\n        else s_timeout.assign(1,1,1,1,0);\n        if (referer) cimg_snprintf(s_referer.assign(1024),1024,\"--referer=%s \",referer);\n        else s_referer.assign(1,1,1,1,0);\n        if (user_agent) cimg_snprintf(s_user_agent.assign(1024),1024,\"--user-agent=\\\"%s\\\" \",user_agent);\n        else s_user_agent.assign(1,1,1,1,0);\n        cimg_snprintf(command,command._width,\n                      \"\\\"%s\\\" --max-redirect=20 %s%s%s-q -r -l 0 --no-cache -O \\\"%s\\\" \\\"%s\\\"\",\n                      cimg::wget_path(),s_timeout._data,s_referer._data,s_user_agent._data,filename_local,\n                      CImg<char>::string(url)._system_strescape().data());\n        cimg::system(command,cimg::wget_path());\n\n        if (cimg::fsize(filename_local)<=0)\n          throw CImgIOException(\"cimg::load_network(): Failed to load file '%s' with external commands \"\n#if cimg_OS==2\n                                \"'wget', 'curl', or 'powershell'.\",url);\n#else\n                                \"'wget' or 'curl'.\",url);\n#endif\n\n        // Try gunzip it.\n        cimg_snprintf(command,command._width,\"%s.gz\",filename_local);\n        std::rename(filename_local,command);\n        cimg_snprintf(command,command._width,\"\\\"%s\\\" --quiet \\\"%s.gz\\\"\",\n                      gunzip_path(),filename_local);\n        cimg::system(command,gunzip_path());\n        if (!cimg::is_file(filename_local)) {\n          cimg_snprintf(command,command._width,\"%s.gz\",filename_local);\n          std::rename(command,filename_local);\n        }\n      }\n","sourceCodeStart":70139,"sourceCodeEnd":70175,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L70139-L70175","documentation":"cimg::load_network() downloads a remote URL to a local file by shelling out to external tools (wget/curl on Linux/macOS, powershell on Windows). After running all configured commands it checks the downloaded file size; if the file is empty or missing (cimg::fsize <= 0) it throws CImgIOException because no external command succeeded in fetching the URL.","triggerScenarios":"Calling CImg<float>::load()/.load_network() (or load_other/load_magick fallbacks) on an http/https/ftp URL when: no wget/curl/powershell binary exists on PATH or their paths (cimg::wget_path/curl_path) are wrong; the URL is malformed, 404, or the server is unreachable; a proxy/firewall blocks the request; the timeout (-timeout-m 5) or max-redirect limit is exceeded; or TLS certificate verification fails.","commonSituations":"Docker/container or CI images without curl/wget installed; offline/air-gapped machines where CImg tries to fetch example images or documentation assets; VPN/proxy environments blocking outbound requests; wrong cimg::path definitions for the external tools; server-side 4xx/5xx responses.","solutions":["Install wget or curl (or on Windows, verify powershell is available) and ensure it is on PATH, or set the correct tool path via cimg::wget_path(...)/cimg::curl_path(...) before loading.","Open the URL in a browser or run `curl -I <url>` manually to confirm the URL is valid, reachable, and returns 200.","Download the file manually (browser/curl) and load the local file with CImg<T>::load() instead of load_network().","Check network/proxy/VPN settings and certificate issues; increase the timeout if the request was cut off."],"exampleFix":"// before\nCImg<unsigned char> img;\nimg.load_network(\"https://example.com/image.jpg\"); // throws if curl/wgit missing or URL unreachable\n// after\nif (std::system(\"command -v curl >/dev/null 2>&1\") == 0) {\n  try {\n    img.load_network(\"https://example.com/image.jpg\");\n  } catch (CImgIOException&) {\n    img.load(\"fallback_image.jpg\"); // local fallback\n  }\n} else {\n  img.load(\"fallback_image.jpg\");\n}","handlingStrategy":"fallback","validationCode":"// Check an external downloader exists and the URL is reachable before load_network()\nbool canDownload(const char* url) {\n  if (std::system(\"command -v wget >/dev/null 2>&1\") != 0 &&\n      std::system(\"command -v curl >/dev/null 2>&1\") != 0) return false;\n  std::string cmd = std::string(\"curl -fsSI --max-time 5 \") + url + \" >/dev/null 2>&1\";\n  return std::system(cmd.c_str()) == 0; // HEAD request succeeds (2xx)\n}\nif (!canDownload(\"https://example.com/image.jpg\")) { /* use local file / skip */ }","typeGuard":null,"tryCatchPattern":"try {\n  img.load_network(url);\n} catch (CImgIOException& e) {\n  std::cerr << \"Network load failed: \" << e.what() << \"\\n\";\n  img.load(local_fallback_path); // or skip with a default image\n}","preventionTips":["Install wget or curl in your runtime image (apt-get install curl) before deploying CImg code that fetches URLs.","Pre-download assets at build time and use CImg<T>::load() on local files instead of load_network() in production.","Validate URLs and test reachability (curl -I) before calling load_network().","Wrap load_network() in try/catch with a local-file fallback for offline robustness."],"tags":["network","external-command","download-failed","cimg"],"backgroundTag":"http-request-failed","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"}