Yalantis/uCrop · error · CImgArgumentException
load_inr(): Specified filename is (null).
Error message
load_inr(): Specified filename is (null).
What it means
CImg's load_inr() loads INRIMAGE (.inr) volumetric image files. The library throws CImgArgumentException when both the std::FILE* handle and the filename C-string are null, because there is no source to read from. This is a pure API-misuse guard raised before any I/O happens.
Source
Thrown at ucrop/src/main/jni/CImg.h:58709
throw CImgIOException("CImg<%s>::load_inr(): Big/Little Endian coding type undefined in header.",
pixel_type());
}
CImg<T>& _load_inr(std::FILE *const file, const char *const filename, float *const voxel_size) {
#define _cimg_load_inr_case(Tf,sign,pixsize,Ts) \
if (!loaded && fopt[6]==pixsize && fopt[4]==Tf && fopt[5]==sign) { \
Ts *xval, *const val = new Ts[(size_t)fopt[0]*fopt[3]]; \
cimg_forYZ(*this,y,z) { \
cimg::fread(val,fopt[0]*fopt[3],nfile); \
if (fopt[7]!=endian) cimg::invert_endianness(val,fopt[0]*fopt[3]); \
xval = val; cimg_forX(*this,x) cimg_forC(*this,c) (*this)(x,y,z,c) = (T)*(xval++); \
} \
delete[] val; \
loaded = true; \
}
if (!file && !filename)
throw CImgArgumentException(_cimg_instance
"load_inr(): Specified filename is (null).",
cimg_instance);
std::FILE *const nfile = file?file:cimg::fopen(filename,"rb");
int fopt[8], endian = cimg::endianness()?1:0;
bool loaded = false;
if (voxel_size) voxel_size[0] = voxel_size[1] = voxel_size[2] = 1;
_load_inr_header(nfile,fopt,voxel_size);
assign(fopt[0],fopt[1],fopt[2],fopt[3]);
_cimg_load_inr_case(0,0,8,unsigned char);
_cimg_load_inr_case(0,1,8,char);
_cimg_load_inr_case(0,0,16,unsigned short);
_cimg_load_inr_case(0,1,16,short);
_cimg_load_inr_case(0,0,32,unsigned int);
_cimg_load_inr_case(0,1,32,int);
_cimg_load_inr_case(1,0,32,float);
_cimg_load_inr_case(1,1,32,float);
_cimg_load_inr_case(1,0,64,double);View on GitHub (pinned to f788b534b4)
Solutions
- Check the filename for null/empty before calling load_inr() and return an error early
- Verify the variable or config value that supplies the path is actually populated
- If using a FILE* variant, ensure the stream was successfully fopen-ed before passing it
Example fix
// before
CImg<float> img;
img.load_inr(path); // path may be NULL
// after
if (!path || !*path) { fprintf(stderr, "no INR file given\n"); return 1; }
CImg<float> img;
img.load_inr(path); Defensive patterns
Strategy: validation
Validate before calling
if (!filename || !*filename) { throw std::invalid_argument("filename required for load_inr"); } Type guard
bool is_valid_path(const char *p) { return p != nullptr && *p != '\0'; } Try / catch
try { img.load_inr(path); } catch (const cimg_library::CImgArgumentException &e) { /* null/invalid argument */ log(e.what()); } Prevention
- Never pass raw getenv()/lookup results straight into loaders; check for null/empty first
- Centralize path resolution in one helper that guarantees a valid string or throws
- Prefer std::string over const char* in your code and only call c_str() after validation
When it happens
Trigger: Calling load_inr(nullptr) on a default-constructed path, or passing a null filename with no open FILE*, e.g. CImg<float> img; img.load_inr(getenv("INR_FILE")) when the env var is unset.
Common situations: Env vars or config values holding the file path are empty/null; a caller computed a path dynamically and it came back NULL; bindings passing null through from another language.
Related errors
- load_jpeg(): Specified filename is (null).
- load_jxl(): Specified filename is (null).
- load_magick(): Specified filename is (null).
- load_pfm(): Specified filename is (null).
- load_rgb(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/a401184fa11d9dda.
Report an issue: GitHub.