Yalantis/uCrop · error · CImgArgumentException

CImgList<%s>::get_unserialize(): CImg header not found in se

Error message

CImgList<%s>::get_unserialize(): CImg header not found in serialized buffer.

What it means

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.

Source

Thrown at ucrop/src/main/jni/CImg.h:68864

        throw CImgArgumentException("CImgList<%s>::get_unserialize(): Specified serialized buffer is (null).",
                                    pixel_type());
      CImgList<T> res;
      const t *stream = buffer._data + header_size, *const estream = buffer._data + buffer.size();
      bool loaded = false, endian = cimg::endianness(), is_bytef = false;
      CImg<charT> tmp(256), str_pixeltype(256), str_endian(256);
      *tmp = *str_pixeltype = *str_endian = 0;
      unsigned int j, N = 0, W, H, D, C;
      uint64T csiz;
      int i, err;
      cimg::unused(is_bytef);
      do {
        j = 0; while ((i=(int)*stream)!='\n' && stream<estream && j<255) { ++stream; tmp[j++] = (char)i; }
        ++stream; tmp[j] = 0;
      } while (*tmp=='#' && stream<estream);
      err = cimg_sscanf(tmp,"%u%*c%255[A-Za-z123468_]%*c%255[sA-Za-z_ ]",
                        &N,str_pixeltype._data,str_endian._data);
      if (err<2)
        throw CImgArgumentException("CImgList<%s>::get_unserialize(): CImg header not found in serialized buffer.",
                                    pixel_type());
      if (!cimg::strncasecmp("little",str_endian,6)) endian = false;
      else if (!cimg::strncasecmp("big",str_endian,3)) endian = true;
      res.assign(N);
      _cimg_unserialize_case("bool",0,0,cimg_uint8);
      _cimg_unserialize_case("uint8","unsigned_char","uchar",cimg_uint8);
      _cimg_unserialize_case("int8",0,0,cimg_int8);
      _cimg_unserialize_case("char",0,0,char);
      _cimg_unserialize_case("uint16","unsigned_short","ushort",cimg_uint16);
      _cimg_unserialize_case("int16","short",0,cimg_int16);
      _cimg_unserialize_case("uint32","unsigned_int","uint",cimg_uint32);
      _cimg_unserialize_case("int32","int",0,cimg_int32);
      _cimg_unserialize_case("uint64","unsigned_int64",0,cimg_uint64);
      _cimg_unserialize_case("int64",0,0,cimg_int64);
      _cimg_unserialize_case("float32","float",0,cimg_float32);
      _cimg_unserialize_case("float64","double",0,cimg_float64);
      if (!loaded)
        throw CImgArgumentException("CImgList<%s>::get_unserialize(): Unsupported pixel type '%s' defined "

View on GitHub (pinned to f788b534b4)

Solutions

  1. Verify the input actually was produced by CImg save()/serialize(); open the file and check the first line matches '<N> <pixeltype> <endian>'.
  2. Use the correct loader (CImg::load_png/load_jpeg etc.) for non-CImg image formats.
  3. Re-export the data from the producer with CImg serialization if the header is damaged.

Example fix

// before
CImgList<float> imgs;
imgs.load("photo.png"); // photo.png is not .cimg -> header not found
// after
CImg<float> img;
img.load("photo.png");        // correct loader for PNG
CImgList<float> imgs(img);    // wrap in a list if needed
Defensive patterns

Strategy: validation

Validate before calling

// Sniff that the stream starts with a CImg header: '<count> <pixeltype> <endian>'
std::ifstream f(path, std::ios::binary);
char line[256]; f.getline(line, 256);
unsigned N; char pt[256], en[256];
if (std::sscanf(line, "%u %255[A-Za-z123468_] %255[sA-Za-z_ ]", &N, pt, en) < 2)
  throw std::runtime_error("file is not in CImg serialized format");

Try / catch

try {
  imgs.unserialize(raw);
} catch (CImgArgumentException& e) {
  cimg::warn("not a CImg serialized buffer: %s", e.what());
  // fall back to format-specific loaders (load_png, load_jpeg ...)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/48c09f5238719abb. Report an issue: GitHub.