{"record":{"id":"39629cbeaaae43be","repo":"Yalantis/uCrop","slug":"get-serialize-unable-to-compress-data-unless-zl","errorCode":null,"errorMessage":"get_serialize(): Unable to compress data unless zlib is enabled, storing them uncompressed.","messagePattern":"get_serialize\\(\\): Unable to compress data unless zlib is enabled, storing them uncompressed\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68733,"sourceCode":"      if (!cimg::path_exists(filename))\n        throw CImgIOException(_cimglist_instance\n                              \"save_ffmpeg_external(): Failed to save file '%s' with external command 'ffmpeg'.\",\n                              cimglist_instance,\n                              filename);\n      cimglist_for(*this,l) std::remove(filenames[l]);\n      return *this;\n    }\n\n    //! Serialize a CImgList<T> instance into a raw CImg<unsigned char> buffer.\n    /**\n       \\param is_compressed tells if zlib compression must be used for serialization\n       (this requires 'cimg_use_zlib' been enabled).\n       \\param header_size Reserve empty bytes as a starting header.\n    **/\n    CImg<ucharT> get_serialize(const bool is_compressed=false, const unsigned int header_size=0) const {\n#ifndef cimg_use_zlib\n      if (is_compressed)\n        cimg::warn(_cimglist_instance\n                   \"get_serialize(): Unable to compress data unless zlib is enabled, \"\n                   \"storing them uncompressed.\",\n                   cimglist_instance);\n#endif\n      CImgList<ucharT> stream;\n      if (header_size) CImg<ucharT>(1,header_size,1,1,0).move_to(stream);\n      CImg<charT> tmpstr(128);\n      const char *const ptype = pixel_type(), *const etype = cimg::endianness()?\"big\":\"little\";\n      cimg_snprintf(tmpstr,tmpstr._width,\"%u %s %s_endian\\n\",_width,ptype,etype);\n      CImg<ucharT>::string(tmpstr,false).move_to(stream);\n      cimglist_for(*this,l) {\n        const CImg<T>& img = _data[l];\n        cimg_snprintf(tmpstr,tmpstr._width,\"%u %u %u %u\",img._width,img._height,img._depth,img._spectrum);\n        CImg<ucharT>::string(tmpstr,false).move_to(stream);\n        if (img._data) {\n          CImg<T> tmp;\n          if (cimg::endianness()) { tmp = img; cimg::invert_endianness(tmp._data,tmp.size()); }\n          const CImg<T>& ref = cimg::endianness()?tmp:img;","sourceCodeStart":68715,"sourceCodeEnd":68751,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68715-L68751","documentation":"CImgList::get_serialize() warns when is_compressed=true was requested but the library was compiled without cimg_use_zlib defined. zlib compression is unavailable, so the data is serialized uncompressed instead of failing. Behavior is still correct, just larger output.","triggerScenarios":"Calling get_serialize(true) (or serialize(true)) on a build of CImg.h where the preprocessor macro cimg_use_zlib is not defined, e.g. a plain vendored CImg.h without -Dcimg_use_zlib and linked zlib.","commonSituations":"Vendoring CImg.h into an Android NDK/jni build (as here) without adding the zlib build flag; upgrading CImg and dropping the compile definition; assuming compression works because zlib exists on the system but was never enabled at compile time.","solutions":["Define cimg_use_zlib in the build (e.g. LOCAL_CFLAGS / cppFlags += '-Dcimg_use_zlib') and link zlib (-lz), then rebuild.","Pass is_compressed=false and accept uncompressed serialization if zlib is not needed.","Check output size or the warning at runtime and switch to an external compression step (gzip the serialized buffer yourself)."],"exampleFix":"// Android.mk before\nLOCAL_CFLAGS := -O2\n// after\nLOCAL_CFLAGS := -O2 -Dcimg_use_zlib\nLOCAL_LDLIBS += -lz","handlingStrategy":"fallback","validationCode":"#ifdef cimg_use_zlib\n  CImg<unsigned char> buf = list.get_serialize(true);\n#else\n  CImg<unsigned char> buf = list.get_serialize(false);\n#endif","typeGuard":null,"tryCatchPattern":"CImg<unsigned char> buf;\nif (compressed_available()) buf = list.get_serialize(true);\nelse { warn_user(\"uncompressed\"); buf = list.get_serialize(false); }","preventionTips":["Define cimg_use_zlib and link -lz in every build config that vendors CImg.h","Add a static_assert or build-time check that required cimg_use_* macros are set","Document required compile flags next to the vendored CImg.h"],"tags":["cimg","zlib","serialization","compile-time","warning"],"backgroundTag":"feature-not-enabled","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"}