{"record":{"id":"8508e24fc4380eb6","repo":"Yalantis/uCrop","slug":"cimglist-s-get-unserialize-unable-to-unseria","errorCode":null,"errorMessage":"CImgList<%s>::get_unserialize(): Unable to unserialize compressed data unless zlib is enabled.","messagePattern":"CImgList<(.+?)>::get_unserialize\\(\\): Unable to unserialize compressed data unless zlib is enabled\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68811,"sourceCode":"    //! Unserialize a CImg<unsigned char> serialized buffer into a CImgList<T> list.\n    template<typename t>\n    static CImgList<T> get_unserialize(const CImg<t>& buffer, const unsigned int header_size=0) {\n#ifdef cimg_use_zlib\n#define _cimgz_unserialize_case(Tss) { \\\n        Bytef *cbuf = 0; \\\n        if (sizeof(t)!=1 || buffer.pixel_type()==cimg::type<bool>::string()) { \\\n          cbuf = new Bytef[csiz]; Bytef *_cbuf = cbuf; \\\n          for (ulongT k = 0; k<csiz && stream<estream; ++k) *(_cbuf++) = (Bytef)*(stream++); \\\n          is_bytef = false; \\\n        } else { cbuf = (Bytef*)stream; stream+=csiz; is_bytef = true; } \\\n        raw.assign(W,H,D,C); \\\n        uLongf destlen = raw.size()*sizeof(Tss); \\\n        uncompress((Bytef*)raw._data,&destlen,cbuf,csiz); \\\n        if (!is_bytef) delete[] cbuf; \\\n      }\n#else\n#define _cimgz_unserialize_case(Tss) \\\n      throw CImgArgumentException(\"CImgList<%s>::get_unserialize(): Unable to unserialize compressed data \" \\\n                                  \"unless zlib is enabled.\", \\\n                                  pixel_type());\n#endif\n\n#define _cimg_unserialize_case(Ts1,Ts2,Ts3,Tss) \\\n      if (!loaded && ((Ts1 && !cimg::strcasecmp(Ts1,str_pixeltype)) || \\\n                      (Ts2 && !cimg::strcasecmp(Ts2,str_pixeltype)) || \\\n                      (Ts3 && !cimg::strcasecmp(Ts3,str_pixeltype)))) { \\\n        for (unsigned int l = 0; l<N; ++l) { \\\n          j = 0; while ((i=(int)*stream)!='\\n' && stream<estream && j<255) { ++stream; tmp[j++] = (char)i; } \\\n          ++stream; tmp[j] = 0; \\\n          W = H = D = C = 0; csiz = 0; \\\n          if ((err = cimg_sscanf(tmp,\"%u %u %u %u #\" cimg_fuint64,&W,&H,&D,&C,&csiz))<4) \\\n            throw CImgArgumentException(\"CImgList<%s>::unserialize(): Invalid specified size (%u,%u,%u,%u) for \" \\\n                                        \"image #%u in serialized buffer.\", \\\n                                        pixel_type(),W,H,D,C,l); \\\n          if (W*H*D*C>0) { \\\n            CImg<Tss> raw; \\","sourceCodeStart":68793,"sourceCodeEnd":68829,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68793-L68829","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (Android.mk)\nLOCAL_CFLAGS := -O3\n// after\nLOCAL_CFLAGS := -O3 -Dcimg_use_zlib\nLOCAL_LDLIBS += -lz","handlingStrategy":"validation","validationCode":"#ifdef cimg_use_zlib\n  imgs.unserialize(raw); // safe: zlib available\n#else\n  #error \"unserializing compressed data requires cimg_use_zlib\"\n#endif","typeGuard":"bool canUnserializeCompressed() { return\n#ifdef cimg_use_zlib\n  true;\n#else\n  false;\n#endif\n}","tryCatchPattern":"try {\n  imgs.unserialize(raw);\n} catch (CImgArgumentException& e) {\n  cimg::warn(\"compressed unserialize unsupported; rebuild with cimg_use_zlib\");\n}","preventionTips":["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)."],"tags":["zlib","serialization","build-configuration","native"],"backgroundTag":"missing-optional-dependency","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"}