Yalantis/uCrop · error · CImgArgumentException
CImgList<%s>::unserialize(): Invalid specified size (%u,%u,%
Error message
CImgList<%s>::unserialize(): Invalid specified size (%u,%u,%u,%u) for image #%u in serialized buffer.
What it means
While parsing a per-image header line ('W H D C #csiz') inside CImgList::unserialize(), cimg_sscanf extracted fewer than 4 unsigned dimensions, meaning the header line does not contain a valid W/H/D/C tuple. CImg throws CImgArgumentException naming the offending image index and the parsed (garbage) dimensions.
Source
Thrown at ucrop/src/main/jni/CImg.h:68825
if (!is_bytef) delete[] cbuf; \
}
#else
#define _cimgz_unserialize_case(Tss) \
throw CImgArgumentException("CImgList<%s>::get_unserialize(): Unable to unserialize compressed data " \
"unless zlib is enabled.", \
pixel_type());
#endif
#define _cimg_unserialize_case(Ts1,Ts2,Ts3,Tss) \
if (!loaded && ((Ts1 && !cimg::strcasecmp(Ts1,str_pixeltype)) || \
(Ts2 && !cimg::strcasecmp(Ts2,str_pixeltype)) || \
(Ts3 && !cimg::strcasecmp(Ts3,str_pixeltype)))) { \
for (unsigned int l = 0; l<N; ++l) { \
j = 0; while ((i=(int)*stream)!='\n' && stream<estream && j<255) { ++stream; tmp[j++] = (char)i; } \
++stream; tmp[j] = 0; \
W = H = D = C = 0; csiz = 0; \
if ((err = cimg_sscanf(tmp,"%u %u %u %u #" cimg_fuint64,&W,&H,&D,&C,&csiz))<4) \
throw CImgArgumentException("CImgList<%s>::unserialize(): Invalid specified size (%u,%u,%u,%u) for " \
"image #%u in serialized buffer.", \
pixel_type(),W,H,D,C,l); \
if (W*H*D*C>0) { \
CImg<Tss> raw; \
CImg<T> &img = res._data[l]; \
if (err==5) _cimgz_unserialize_case(Tss) \
else { \
raw.assign(W,H,D,C); \
CImg<ucharT> _raw((unsigned char*)raw._data,W*sizeof(Tss),H,D,C,true); \
if (sizeof(t)==1) { std::memcpy(_raw,stream,_raw.size()); stream+=_raw.size(); } \
else cimg_for(_raw,p,unsigned char) *p = (unsigned char)*(stream++); \
} \
if (endian!=cimg::endianness()) cimg::invert_endianness(raw._data,raw.size()); \
raw.move_to(img); \
} \
} \
loaded = true; \
}View on GitHub (pinned to f788b534b4)
Solutions
- Regenerate the serialized file with a matching CImg version; verify it round-trips (save then load).
- Check the file for truncation/corruption — compare byte size or checksum against the producer.
- Ensure binary-safe transfer (ftp binary mode, no text-mode conversion).
- Confirm you are calling unserialize() on a CImg-format buffer, not an arbitrary file.
Example fix
// before
CImgList<float> imgs;
imgs.load("possibly_truncated.cimg");
// after
std::ifstream f("possibly_truncated.cimg", std::ios::binary|std::ios::ate);
if (f.tellg() < 16) throw std::runtime_error("file too small to be valid .cimg");
CImgList<float> imgs;
imgs.load("possibly_truncated.cimg"); Defensive patterns
Strategy: validation
Validate before calling
// Validate the buffer looks like .cimg before loading
std::ifstream f(path, std::ios::binary);
char line[256]; f.getline(line, 256);
unsigned N, W, H, D, C;
if (std::sscanf(line, "%u %u %u %u", &W, &H, &D, &C) < 1)
throw std::runtime_error("not a valid CImg serialized buffer"); Try / catch
try {
imgs.unserialize(raw);
} catch (CImgArgumentException& e) {
cimg::warn("corrupt serialized buffer: %s", e.what());
// discard / re-request the data
} Prevention
- Verify checksums/size of serialized files after transfer.
- Use binary-safe transfer channels.
- Round-trip test (save then load) in CI.
- Never feed non-CImg files to unserialize().
When it happens
Trigger: Passing a corrupted, truncated, or wrongly-formatted buffer to CImgList::load()/unserialize() where the header line for image #l is missing dimensions or contains non-numeric text (e.g. an HTML error page, a text file, or a partially written save).
Common situations: File truncated by an interrupted save; loading a plain-text or non-CImg file into unserialize(); version mismatch where the .cimg header layout changed; transferring binary files in text mode corrupting newline/dimension lines.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- CImgList<%s>::get_unserialize(): CImg header not found in se
- CImgList<%s>::get_unserialize(): Unsupported pixel type '%s'
- CImgList<%s>::get_unserialize(): Unable to unserialize compr
- CImgList<%s>::get_unserialize(): Specified serialized buffer
- load_cimg(): Invalid specified size (%u,%u,%u,%u) of image %
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/5d640d60ef504612.
Report an issue: GitHub.