Yalantis/uCrop · error · CImgIOException

load_tiff(): Invalid strip in file '%s'.

Error message

load_tiff(): Invalid strip in file '%s'.

What it means

For strip-based TIFFs (single sample per pixel), load_tiff() computes each strip with TIFFComputeStrip and decodes it via TIFFReadEncodedStrip(). A negative return means the strip is corrupt or truncated, so the library throws a CImgIOException.

Source

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

                  (*this)(cc,rr,vv) = (T)*(ptr++);
            }
        _TIFFfree(buf);
      }
    }

    template<typename t>
    void _load_tiff_contig(TIFF *const tif, const cimg_uint16 samplesperpixel,
                           const cimg_uint32 nx, const cimg_uint32 ny) {
      t *const buf = (t*)_TIFFmalloc(TIFFStripSize(tif));
      if (buf) {
        cimg_uint32 row, rowsperstrip = (cimg_uint32)-1;
        TIFFGetField(tif,TIFFTAG_ROWSPERSTRIP,&rowsperstrip);
        for (row = 0; row<ny; row+= rowsperstrip) {
          cimg_uint32 nrow = (row + rowsperstrip>ny?ny - row:rowsperstrip);
          tstrip_t strip = TIFFComputeStrip(tif, row, 0);
          if ((TIFFReadEncodedStrip(tif,strip,buf,-1))<0) {
            _TIFFfree(buf); TIFFClose(tif);
            throw CImgIOException(_cimg_instance
                                  "load_tiff(): Invalid strip in file '%s'.",
                                  cimg_instance,
                                  TIFFFileName(tif));
          }
          const t *ptr = buf;
          for (unsigned int rr = 0; rr<nrow; ++rr)
            for (unsigned int cc = 0; cc<nx; ++cc)
              for (unsigned int vv = 0; vv<samplesperpixel; ++vv) (*this)(cc,row + rr,vv) = (T)*(ptr++);
        }
        _TIFFfree(buf);
      }
    }

    template<typename t>
    void _load_tiff_separate(TIFF *const tif, const cimg_uint16 samplesperpixel,
                             const cimg_uint32 nx, const cimg_uint32 ny) {
      t *buf = (t*)_TIFFmalloc(TIFFStripSize(tif));
      if (buf) {

View on GitHub (pinned to f788b534b4)

Solutions

  1. Rewrite the file with tiffcp to regenerate valid strips.
  2. Validate with tiffinfo/tiffdump to confirm strip offsets and byte counts.
  3. Re-export or re-download the source image.
  4. Wrap the call in try/catch and use a fallback loader.

Example fix

// before
img.load_tiff("stripped.tif");
// after
// $ tiffcp stripped.tif fixed.tif
img.load_tiff("fixed.tif");
Defensive patterns

Strategy: try-catch

Validate before calling

std::ifstream f(path, std::ios::binary | std::ios::ate);
if (f.tellg() < 256) throw std::runtime_error("TIFF truncated");

Try / catch

try { img.load_tiff(path); }
catch (CImgIOException &e) { log("strip decode failed"); retryWithRepairedFile(path); }

Prevention

When it happens

Trigger: Loading a stripped TIFF whose strip data is damaged, e.g. TIFFReadEncodedStrip returns < 0 for some row band.

Common situations: Files truncated mid-transfer, corruption from faulty storage or parsers writing wrong RowsPerStrip metadata.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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