{"record":{"id":"3b8147efb1726bd4","repo":"Yalantis/uCrop","slug":"load-tiff-invalid-strip-in-file-s","errorCode":null,"errorMessage":"load_tiff(): Invalid strip in file '%s'.","messagePattern":"load_tiff\\(\\): Invalid strip in file '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58105,"sourceCode":"                  (*this)(cc,rr,vv) = (T)*(ptr++);\n            }\n        _TIFFfree(buf);\n      }\n    }\n\n    template<typename t>\n    void _load_tiff_contig(TIFF *const tif, const cimg_uint16 samplesperpixel,\n                           const cimg_uint32 nx, const cimg_uint32 ny) {\n      t *const buf = (t*)_TIFFmalloc(TIFFStripSize(tif));\n      if (buf) {\n        cimg_uint32 row, rowsperstrip = (cimg_uint32)-1;\n        TIFFGetField(tif,TIFFTAG_ROWSPERSTRIP,&rowsperstrip);\n        for (row = 0; row<ny; row+= rowsperstrip) {\n          cimg_uint32 nrow = (row + rowsperstrip>ny?ny - row:rowsperstrip);\n          tstrip_t strip = TIFFComputeStrip(tif, row, 0);\n          if ((TIFFReadEncodedStrip(tif,strip,buf,-1))<0) {\n            _TIFFfree(buf); TIFFClose(tif);\n            throw CImgIOException(_cimg_instance\n                                  \"load_tiff(): Invalid strip in file '%s'.\",\n                                  cimg_instance,\n                                  TIFFFileName(tif));\n          }\n          const t *ptr = buf;\n          for (unsigned int rr = 0; rr<nrow; ++rr)\n            for (unsigned int cc = 0; cc<nx; ++cc)\n              for (unsigned int vv = 0; vv<samplesperpixel; ++vv) (*this)(cc,row + rr,vv) = (T)*(ptr++);\n        }\n        _TIFFfree(buf);\n      }\n    }\n\n    template<typename t>\n    void _load_tiff_separate(TIFF *const tif, const cimg_uint16 samplesperpixel,\n                             const cimg_uint32 nx, const cimg_uint32 ny) {\n      t *buf = (t*)_TIFFmalloc(TIFFStripSize(tif));\n      if (buf) {","sourceCodeStart":58087,"sourceCodeEnd":58123,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58087-L58123","documentation":"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.","triggerScenarios":"Loading a stripped TIFF whose strip data is damaged, e.g. TIFFReadEncodedStrip returns < 0 for some row band.","commonSituations":"Files truncated mid-transfer, corruption from faulty storage or parsers writing wrong RowsPerStrip metadata.","solutions":["Rewrite the file with tiffcp to regenerate valid strips.","Validate with tiffinfo/tiffdump to confirm strip offsets and byte counts.","Re-export or re-download the source image.","Wrap the call in try/catch and use a fallback loader."],"exampleFix":"// before\nimg.load_tiff(\"stripped.tif\");\n// after\n// $ tiffcp stripped.tif fixed.tif\nimg.load_tiff(\"fixed.tif\");","handlingStrategy":"try-catch","validationCode":"std::ifstream f(path, std::ios::binary | std::ios::ate);\nif (f.tellg() < 256) throw std::runtime_error(\"TIFF truncated\");","typeGuard":null,"tryCatchPattern":"try { img.load_tiff(path); }\ncatch (CImgIOException &e) { log(\"strip decode failed\"); retryWithRepairedFile(path); }","preventionTips":["Validate strip offsets/byte counts with tiffdump","Re-download truncated files","Rewrite third-party TIFFs with tiffcp before use"],"tags":["cimg","tiff","corrupt-file"],"backgroundTag":"file-read-failed","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"}