{"record":{"id":"887f0f9047050031","repo":"Yalantis/uCrop","slug":"load-medcon-external-specified-filename-is-nul","errorCode":null,"errorMessage":"load_medcon_external(): Specified filename is (null) or does not exist.","messagePattern":"load_medcon_external\\(\\): Specified filename is \\(null\\) or does not exist\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59863,"sourceCode":"#else\n      load_pnm(filename_tmp);\n#endif\n      std::remove(filename_tmp);\n      return *this;\n    }\n\n    //! Load image using ImageMagick's external tool 'convert' \\newinstance.\n    static CImg<T> get_load_imagemagick_external(const char *const filename) {\n      return CImg<T>().load_imagemagick_external(filename);\n    }\n\n    //! Load image from a DICOM file, using Medcon's external tool 'medcon'.\n    /**\n       \\param filename Filename, as a C-string.\n    **/\n    CImg<T>& load_medcon_external(const char *const filename) {\n      if (!filename || !cimg::is_file(filename))\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_medcon_external(): Specified filename is (null) or does not exist.\",\n                                    cimg_instance);\n      CImg<charT> command(1024), filename_tmp(256), body(256);\n      do {\n        cimg_snprintf(filename_tmp,filename_tmp._width,\"%s.hdr\",cimg::filenamerand());\n      } while (cimg::path_exists(filename_tmp));\n      cimg_snprintf(command,command._width,\"\\\"%s\\\" -w -c anlz -o \\\"%s\\\" -f \\\"%s\\\"\",\n                    cimg::medcon_path(),\n                    CImg<charT>::string(filename_tmp)._system_strescape().data(),\n                    CImg<charT>::string(filename)._system_strescape().data());\n      cimg::system(command,cimg::medcon_path());\n      cimg::split_filename(filename_tmp,body);\n\n      cimg_snprintf(command,command._width,\"%s.hdr\",body._data);\n      if (!cimg::path_exists(command)) {\n        cimg_snprintf(command,command._width,\"m000-%s.hdr\",body._data);\n        if (!cimg::path_exists(command)) {\n          throw CImgIOException(_cimg_instance","sourceCodeStart":59845,"sourceCodeEnd":59881,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59845-L59881","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nimg.load_medcon_external(cfg.dicomPath); // may be null/missing\n// after\nif (!cfg.dicomPath || !cimg::is_file(cfg.dicomPath))\n  throw std::invalid_argument(\"DICOM file missing: \" + std::string(cfg.dicomPath?cfg.dicomPath:\"(null)\"));\nimg.load_medcon_external(cfg.dicomPath);","handlingStrategy":"validation","validationCode":"if (!path || !cimg::is_file(path))\n  throw std::invalid_argument(\"DICOM path null or does not exist\");","typeGuard":"bool isExistingFile(const char* p){ return p && cimg::is_file(p); }","tryCatchPattern":"try { img.load_medcon_external(path); }\ncatch (CImgArgumentException& e) { log(\"bad DICOM path\"); }","preventionTips":["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"],"tags":["dicom","argument-validation","file","cimg"],"backgroundTag":"file-not-found","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"}