{"record":{"id":"48c09f5238719abb","repo":"Yalantis/uCrop","slug":"cimglist-s-get-unserialize-cimg-header-not-f","errorCode":null,"errorMessage":"CImgList<%s>::get_unserialize(): CImg header not found in serialized buffer.","messagePattern":"CImgList<(.+?)>::get_unserialize\\(\\): CImg header not found in serialized buffer\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68864,"sourceCode":"        throw CImgArgumentException(\"CImgList<%s>::get_unserialize(): Specified serialized buffer is (null).\",\n                                    pixel_type());\n      CImgList<T> res;\n      const t *stream = buffer._data + header_size, *const estream = buffer._data + buffer.size();\n      bool loaded = false, endian = cimg::endianness(), is_bytef = false;\n      CImg<charT> tmp(256), str_pixeltype(256), str_endian(256);\n      *tmp = *str_pixeltype = *str_endian = 0;\n      unsigned int j, N = 0, W, H, D, C;\n      uint64T csiz;\n      int i, err;\n      cimg::unused(is_bytef);\n      do {\n        j = 0; while ((i=(int)*stream)!='\\n' && stream<estream && j<255) { ++stream; tmp[j++] = (char)i; }\n        ++stream; tmp[j] = 0;\n      } while (*tmp=='#' && stream<estream);\n      err = cimg_sscanf(tmp,\"%u%*c%255[A-Za-z123468_]%*c%255[sA-Za-z_ ]\",\n                        &N,str_pixeltype._data,str_endian._data);\n      if (err<2)\n        throw CImgArgumentException(\"CImgList<%s>::get_unserialize(): CImg header not found in serialized buffer.\",\n                                    pixel_type());\n      if (!cimg::strncasecmp(\"little\",str_endian,6)) endian = false;\n      else if (!cimg::strncasecmp(\"big\",str_endian,3)) endian = true;\n      res.assign(N);\n      _cimg_unserialize_case(\"bool\",0,0,cimg_uint8);\n      _cimg_unserialize_case(\"uint8\",\"unsigned_char\",\"uchar\",cimg_uint8);\n      _cimg_unserialize_case(\"int8\",0,0,cimg_int8);\n      _cimg_unserialize_case(\"char\",0,0,char);\n      _cimg_unserialize_case(\"uint16\",\"unsigned_short\",\"ushort\",cimg_uint16);\n      _cimg_unserialize_case(\"int16\",\"short\",0,cimg_int16);\n      _cimg_unserialize_case(\"uint32\",\"unsigned_int\",\"uint\",cimg_uint32);\n      _cimg_unserialize_case(\"int32\",\"int\",0,cimg_int32);\n      _cimg_unserialize_case(\"uint64\",\"unsigned_int64\",0,cimg_uint64);\n      _cimg_unserialize_case(\"int64\",0,0,cimg_int64);\n      _cimg_unserialize_case(\"float32\",\"float\",0,cimg_float32);\n      _cimg_unserialize_case(\"float64\",\"double\",0,cimg_float64);\n      if (!loaded)\n        throw CImgArgumentException(\"CImgList<%s>::get_unserialize(): Unsupported pixel type '%s' defined \"","sourceCodeStart":68846,"sourceCodeEnd":68882,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68846-L68882","documentation":"CImgList::get_unserialize() could not parse the CImg header line, which must look like 'N pixeltype endianess'. cimg_sscanf extracted fewer than 2 fields (count and pixel type), so the stream does not begin with a valid CImg serialized header. CImg throws CImgArgumentException.","triggerScenarios":"Calling unserialize()/load() on data that is not in CImg .cimg format — e.g. a PNG/JPEG, random binary, or a text file — or a buffer whose header_size offset skips past the actual header; corrupted first line.","commonSituations":"Users pointing .cimg loaders at image files with the wrong extension; mixing raw binary dumps with CImg serialized format; manual header edits that broke the 'count pixeltype endian' layout.","solutions":["Verify the input actually was produced by CImg save()/serialize(); open the file and check the first line matches '<N> <pixeltype> <endian>'.","Use the correct loader (CImg::load_png/load_jpeg etc.) for non-CImg image formats.","Re-export the data from the producer with CImg serialization if the header is damaged."],"exampleFix":"// before\nCImgList<float> imgs;\nimgs.load(\"photo.png\"); // photo.png is not .cimg -> header not found\n// after\nCImg<float> img;\nimg.load(\"photo.png\");        // correct loader for PNG\nCImgList<float> imgs(img);    // wrap in a list if needed","handlingStrategy":"validation","validationCode":"// Sniff that the stream starts with a CImg header: '<count> <pixeltype> <endian>'\nstd::ifstream f(path, std::ios::binary);\nchar line[256]; f.getline(line, 256);\nunsigned N; char pt[256], en[256];\nif (std::sscanf(line, \"%u %255[A-Za-z123468_] %255[sA-Za-z_ ]\", &N, pt, en) < 2)\n  throw std::runtime_error(\"file is not in CImg serialized format\");","typeGuard":null,"tryCatchPattern":"try {\n  imgs.unserialize(raw);\n} catch (CImgArgumentException& e) {\n  cimg::warn(\"not a CImg serialized buffer: %s\", e.what());\n  // fall back to format-specific loaders (load_png, load_jpeg ...)\n}","preventionTips":["Use the format-specific loader matching each file type.","Check magic bytes / header line before unserialize.","Keep producers and consumers on compatible CImg versions."],"tags":["serialization","parsing","wrong-format","native"],"backgroundTag":"invalid-argument-format","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"}