Yalantis/uCrop · error · CImgArgumentException
CImgList<%s>::get_unserialize(): Unable to unserialize compr
Error message
CImgList<%s>::get_unserialize(): Unable to unserialize compressed data unless zlib is enabled.
What it means
CImgList::get_unserialize() encountered a zlib-compressed image entry in the serialized buffer, but this build of CImg was compiled without the cimg_use_zlib flag. The _cimgz_unserialize_case macro falls back to a throw instead of decompressing. The data itself is fine; the library build lacks the capability.
Source
Thrown at ucrop/src/main/jni/CImg.h:68811
//! Unserialize a CImg<unsigned char> serialized buffer into a CImgList<T> list.
template<typename t>
static CImgList<T> get_unserialize(const CImg<t>& buffer, const unsigned int header_size=0) {
#ifdef cimg_use_zlib
#define _cimgz_unserialize_case(Tss) { \
Bytef *cbuf = 0; \
if (sizeof(t)!=1 || buffer.pixel_type()==cimg::type<bool>::string()) { \
cbuf = new Bytef[csiz]; Bytef *_cbuf = cbuf; \
for (ulongT k = 0; k<csiz && stream<estream; ++k) *(_cbuf++) = (Bytef)*(stream++); \
is_bytef = false; \
} else { cbuf = (Bytef*)stream; stream+=csiz; is_bytef = true; } \
raw.assign(W,H,D,C); \
uLongf destlen = raw.size()*sizeof(Tss); \
uncompress((Bytef*)raw._data,&destlen,cbuf,csiz); \
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; \View on GitHub (pinned to f788b534b4)
Solutions
- Recompile CImg with cimg_use_zlib defined and link the target against zlib (-lz).
- If the buffer format is under your control, serialize uncompressed data from the producer side.
- Ensure the same CImg feature flags are used on both the writing and reading builds.
Example fix
// before (Android.mk) LOCAL_CFLAGS := -O3 // after LOCAL_CFLAGS := -O3 -Dcimg_use_zlib LOCAL_LDLIBS += -lz
Defensive patterns
Strategy: validation
Validate before calling
#ifdef cimg_use_zlib imgs.unserialize(raw); // safe: zlib available #else #error "unserializing compressed data requires cimg_use_zlib" #endif
Type guard
bool canUnserializeCompressed() { return
#ifdef cimg_use_zlib
true;
#else
false;
#endif
} Try / catch
try {
imgs.unserialize(raw);
} catch (CImgArgumentException& e) {
cimg::warn("compressed unserialize unsupported; rebuild with cimg_use_zlib");
} Prevention
- Keep CImg feature flags identical across producer and consumer builds.
- Link zlib (-lz) whenever you serialize large data.
- Document required defines in your build system (Android.mk/CMake).
When it happens
Trigger: Unserializing a buffer produced by a zlib-enabled CImg build (serialized with compression, csiz field set) into a build compiled without -Dcimg_use_zlib and linked against zlib.
Common situations: Cross-platform serialization: data saved on a desktop Linux build with zlib is read on an Android NDK build (e.g. ucrop's jni) where zlib was never enabled; upgrading/downgrading builds changes feature flags.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- load_cimg(): Unable to load compressed data from file '%s' u
- CImgList<%s>::unserialize(): Invalid specified size (%u,%u,%
- CImgList<%s>::get_unserialize(): Specified serialized buffer
- CImgList<%s>::get_unserialize(): CImg header not found in se
- CImgList<%s>::get_unserialize(): Unsupported pixel type '%s'
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/8508e24fc4380eb6.
Report an issue: GitHub.