Yalantis/uCrop · error · CImgIOException

load_pandore(): File size %lu for filename '%s' does not mat

Error message

load_pandore(): File size %lu for filename '%s' does not match encoded image dimensions (%d,%d,%d,%d).

What it means

_load_pandore() validates that the PANDORE file is large enough to actually contain the image dimensions declared in its header (width*height*depth*dim vs the file size). If the decoded dimensions imply more data than the file holds, CImg throws CImgIOException. This catches truncated or corrupt PANDORE files before out-of-bounds reads.

Source

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

      return CImg<T>().load_pandore(filename);
    }

    //! Load image from a PANDORE-5 file \overloading.
    CImg<T>& load_pandore(std::FILE *const file) {
      return _load_pandore(file,0);
    }

    //! Load image from a PANDORE-5 file \newinstance.
    static CImg<T> get_load_pandore(std::FILE *const file) {
      return CImg<T>().load_pandore(file);
    }

    CImg<T>& _load_pandore(std::FILE *const file, const char *const filename) {
#define __cimg_load_pandore_case(nbdim,nwidth,nheight,ndepth,ndim,stype) \
        cimg::fread(dims,nbdim,nfile); \
        if (endian) cimg::invert_endianness(dims,nbdim); \
        if ((ulongT)nwidth*nheight*ndepth*ndim>fsiz) \
          throw CImgIOException(_cimg_instance \
                                "load_pandore(): File size %lu for filename '%s' does not match "\
                                "encoded image dimensions (%d,%d,%d,%d).",\
                                cimg_instance,\
                                (long)fsiz,filename?filename:"(FILE*)",\
                                (int)nwidth,(int)nheight,(int)ndepth,(int)ndim); \
        assign(nwidth,nheight,ndepth,ndim); \
        const size_t siz = size(); \
        stype *buffer = new stype[siz]; \
        cimg::fread(buffer,siz,nfile); \
        if (endian) cimg::invert_endianness(buffer,siz); \
        T *ptrd = _data; \
        cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++); \
        buffer-=siz; \
        delete[] buffer

#define _cimg_load_pandore_case(nbdim,nwidth,nheight,ndepth,dim,stype1,stype2,stype3,ltype) { \
        if (sizeof(stype1)==ltype) { __cimg_load_pandore_case(nbdim,nwidth,nheight,ndepth,dim,stype1); } \
        else if (sizeof(stype2)==ltype) { __cimg_load_pandore_case(nbdim,nwidth,nheight,ndepth,dim,stype2); } \

View on GitHub (pinned to f788b534b4)

Solutions

  1. Re-download or re-copy the file — it is most likely truncated
  2. Verify the file size against the header dims yourself before loading
  3. Re-export the file from the PANDORE tool with correct metadata
  4. Check for disk/transfer corruption (checksum comparison with the original)

Example fix

// before
img.load_pandore(path); // throws on truncated file
// after
struct stat st;
if (stat(path, &st) != 0 || st.st_size < 32)
  throw std::runtime_error("PANDORE file missing or too small");
// optionally sanity-check header dims vs st.st_size, then:
img.load_pandore(path);
Defensive patterns

Strategy: validation

Validate before calling

struct stat st;
if (stat(path,&st)!=0 || st.st_size < 32) throw std::runtime_error("file missing or truncated");
// optionally parse the header dims yourself and require dims product*sizeof <= st.st_size

Try / catch

try { img.load_pandore(path); } catch (const cimg_library::CImgIOException &e) { /* size/dims mismatch = corrupt or truncated */ reject_file(path); }

Prevention

When it happens

Trigger: Reading a truncated .pandore/.pan file; a header with wrong/garbled dimension fields; a file whose declared dims were modified or written by a buggy exporter.

Common situations: Incomplete downloads or interrupted copies; files created by a different/older PANDORE writer with mismatched header; corruption during transfer.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


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