tools/tiff2ps.c:1621: error: Buffer Overrun L3
  Offset: [1, +oo] Size: [0, +oo] by call to `TIFFReadDirectory`.

tools/tiff2ps.c:1486:1: Parameter `tif->tif_dir.td_stripoffset_p`
1484.  */
1485. 
1486. int TIFF2PS(FILE* fd, TIFF* tif, double pgwidth, double pgheight, double lm, double bm, int center)
      ^
1487.   {
1488.   uint32 pixwidth = 0, pixheight = 0;  /* Image width and height in pixels */

tools/tiff2ps.c:1621:59: Call
1619.     rotation = 0.0;
1620.   TIFFGetFieldDefaulted(tif, TIFFTAG_SUBFILETYPE, &subfiletype);
1621.   } while (((subfiletype & FILETYPE_PAGE) || printAll) && TIFFReadDirectory(tif));
                                                                ^
1622. 
1623. return(npages);

libtiff/tif_dirread.c:3920:42: Call
  3918.                                         goto bad;
  3919.                                     }
  3920.                                     if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripoffset_p))  
                                                 ^
  3921.                                             goto bad;
  3922.                                 }

libtiff/tif_dirread.c:5621:1: Parameter `**lpp`
    5619.  * While this routine says "strips", in fact it's also used for tiles.
    5620.  */
    5621. static int
          ^
    5622. TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, uint32 nstrips, uint64** lpp)
    5623. {

libtiff/tif_dirread.c:4269:13: Call
  4267.             TIFFStripSize64(tif) > 0x7FFFFFFFUL )
  4268.         {
  4269.             TryChopUpUncompressedBigTiff(tif);
                    ^
  4270.         }
  4271. 

libtiff/tif_dirread.c:5900:10: Assignment
    5898. 
    5899.     /* Check that the strips are contiguous and of the expected size */
    5900.     for( i = 0; i < td->td_nstrips; i++ )
                   ^
    5901.     {
    5902.         if( i == td->td_nstrips - 1 )

libtiff/tif_dirread.c:5916:26: Call
    5914.                 return;
    5915.             }
    5916.             if( i > 0 && TIFFGetStrileOffset(tif, i) !=
                                   ^
    5917.                     TIFFGetStrileOffset(tif, i-1) + TIFFGetStrileByteCount(tif, i-1) )
    5918.             {

libtiff/tif_dirread.c:6233:1: Parameter `strile`
      6231. 
      6232. /* Return the value of the TileOffsets/StripOffsets array for the specified tile/strile */
      6233. uint64 TIFFGetStrileOffset(TIFF *tif, uint32 strile)
            ^
      6234. {
      6235.     return TIFFGetStrileOffsetWithErr(tif, strile, NULL);

libtiff/tif_dirread.c:6235:12: Call
      6233. uint64 TIFFGetStrileOffset(TIFF *tif, uint32 strile)
      6234. {
      6235.     return TIFFGetStrileOffsetWithErr(tif, strile, NULL);
                       ^
      6236. }
      6237. 

libtiff/tif_dirread.c:6239:1: Parameter `strile`
        6237. 
        6238. /* Return the value of the TileOffsets/StripOffsets array for the specified tile/strile */
        6239. uint64 TIFFGetStrileOffsetWithErr(TIFF *tif, uint32 strile, int *pbErr)
              ^
        6240. {
        6241.     TIFFDirectory *td = &tif->tif_dir;

libtiff/tif_dirread.c:6242:12: Call
        6240. {
        6241.     TIFFDirectory *td = &tif->tif_dir;
        6242.     return _TIFFGetStrileOffsetOrByteCountValue(tif, strile,
                         ^
        6243.                                &(td->td_stripoffset_entry),
        6244.                                &(td->td_stripoffset_p), pbErr);

libtiff/tif_dirread.c:6191:1: Parameter `strile`
          6189. }
          6190. 
          6191. static uint64 _TIFFGetStrileOffsetOrByteCountValue(TIFF *tif, uint32 strile,
                ^
          6192.                                                    TIFFDirEntry* dirent,
          6193.                                                    uint64** parray,

libtiff/tif_dirread.c:6215:19: Call
          6213.         else
          6214.         {
          6215.              if( !_TIFFFetchStrileValue(tif, strile, dirent, parray) )
                                  ^
          6216.              {
          6217.                 if( pbErr )

libtiff/tif_dirread.c:6088:1: <Offset trace>
6086. }
6087. 
6088. static int _TIFFFetchStrileValue(TIFF* tif,
      ^
6089.                                  uint32 strile,
6090.                                  TIFFDirEntry* dirent,

libtiff/tif_dirread.c:6088:1: Parameter `strile`
            6086. }
            6087. 
            6088. static int _TIFFFetchStrileValue(TIFF* tif,
                  ^
            6089.                                  uint32 strile,
            6090.                                  TIFFDirEntry* dirent,

libtiff/tif_dirread.c:6088:1: <Length trace>
6086. }
6087. 
6088. static int _TIFFFetchStrileValue(TIFF* tif,
      ^
6089.                                  uint32 strile,
6090.                                  TIFFDirEntry* dirent,

libtiff/tif_dirread.c:6088:1: Parameter `**parray`
            6086. }
            6087. 
            6088. static int _TIFFFetchStrileValue(TIFF* tif,
                  ^
            6089.                                  uint32 strile,
            6090.                                  TIFFDirEntry* dirent,

libtiff/tif_dirread.c:6179:10: Array access: Offset: [1, +oo] Size: [0, +oo] by call to `TIFFReadDirectory` 
            6177.         return 0;
            6178. 
            6179.     if( ~((*parray)[strile]) == 0 )
                           ^
            6180.     {
            6181.         if( !_TIFFPartialReadStripArray( tif, dirent, strile, *parray ) )

static int _TIFFFetchStrileValue(TIFF* tif,
                                 uint32 strile,
                                 TIFFDirEntry* dirent,
                                 uint64** parray)
{
    static const char module[] = "_TIFFFetchStrileValue";
    TIFFDirectory *td = &tif->tif_dir;
    if( strile >= dirent->tdir_count )
    {
        return 0;
    }
    if( strile >= td->td_stripoffsetbyteallocsize )
    {
        uint32 nStripArrayAllocBefore = td->td_stripoffsetbyteallocsize;
        uint32 nStripArrayAllocNew;
        uint64 nArraySize64;
        size_t nArraySize;
        uint64* offsetArray;
        uint64* bytecountArray;
        if( strile > 1000000 )
        {
            uint64 filesize = TIFFGetFileSize(tif);
            if( strile > filesize / sizeof(uint32) )
            {
                TIFFErrorExt(tif->tif_clientdata, module, "File too short");
                return 0;
            }
        }
        if( td->td_stripoffsetbyteallocsize == 0 &&
            td->td_nstrips < 1024 * 1024 )
        {
            nStripArrayAllocNew = td->td_nstrips;
        }
        else
        {
#define TIFF_MAX(a,b) (((a)>(b)) ? (a) : (b))
#define TIFF_MIN(a,b) (((a)<(b)) ? (a) : (b))
            nStripArrayAllocNew = TIFF_MAX(strile + 1, 1024U * 512U );
            if( nStripArrayAllocNew < 0xFFFFFFFFU / 2  )
                nStripArrayAllocNew *= 2;
            nStripArrayAllocNew = TIFF_MIN(nStripArrayAllocNew, td->td_nstrips);
        }
        assert( strile < nStripArrayAllocNew );
        nArraySize64 = (uint64)sizeof(uint64) * nStripArrayAllocNew;
        nArraySize = (size_t)(nArraySize64);
#if SIZEOF_SIZE_T == 4
        if( nArraySize != nArraySize64 )
        {
            TIFFErrorExt(tif->tif_clientdata, module,
                        "Cannot allocate strip offset and bytecount arrays");
            return 0;
        }
#endif
        offsetArray = (uint64*)(
            _TIFFrealloc( td->td_stripoffset_p, nArraySize ) );
        bytecountArray = (uint64*)(
            _TIFFrealloc( td->td_stripbytecount_p, nArraySize ) );
        if( offsetArray )
            td->td_stripoffset_p = offsetArray;
        if( bytecountArray )
            td->td_stripbytecount_p = bytecountArray;
        if( offsetArray && bytecountArray )
        {
            td->td_stripoffsetbyteallocsize = nStripArrayAllocNew;
            memset(td->td_stripoffset_p + nStripArrayAllocBefore,
                0xFF,
                (td->td_stripoffsetbyteallocsize - nStripArrayAllocBefore) * sizeof(uint64) );
            memset(td->td_stripbytecount_p + nStripArrayAllocBefore,
                0xFF,
                (td->td_stripoffsetbyteallocsize - nStripArrayAllocBefore) * sizeof(uint64) );
        }
        else
        {
            TIFFErrorExt(tif->tif_clientdata, module,
                        "Cannot allocate strip offset and bytecount arrays");
            _TIFFfree(td->td_stripoffset_p);
            td->td_stripoffset_p = NULL;
            _TIFFfree(td->td_stripbytecount_p);
            td->td_stripbytecount_p = NULL;
            td->td_stripoffsetbyteallocsize = 0;
        }
    }
    if( *parray == NULL || strile >= td->td_stripoffsetbyteallocsize )
        return 0;
    if( ~((*parray)[strile]) == 0 )
    {
        if( !_TIFFPartialReadStripArray( tif, dirent, strile, *parray ) )
        {
            (*parray)[strile] = 0;
            return 0;
        }
    }
    return 1;
}
['int TIFF2PS(FILE* fd, TIFF* tif, double pgwidth, double pgheight, double lm, double bm, int center)\n  {\n  uint32 pixwidth = 0, pixheight = 0;\n  double ox = 0.0, oy = 0.0;\n  double pswidth, psheight;\n  double view_width, view_height;\n  double scale = 1.0;\n  double left_offset = lm * PS_UNIT_SIZE;\n  double bottom_offset = bm * PS_UNIT_SIZE;\n  uint32 subfiletype;\n  uint16* sampleinfo;\n  static int npages = 0;\n  if (!TIFFGetField(tif, TIFFTAG_XPOSITION, &ox))\n     ox = 0;\n  if (!TIFFGetField(tif, TIFFTAG_YPOSITION, &oy))\n     oy = 0;\n  do {\n     tf_numberstrips = TIFFNumberOfStrips(tif);\n     TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &tf_rowsperstrip);\n     TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample);\n     TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);\n     TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfiguration);\n     TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression);\n     TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, &extrasamples, &sampleinfo);\n     alpha = (extrasamples == 1 && sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);\n     if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric))\n       {\n       switch (samplesperpixel - extrasamples)\n             {\n            case 1: if (isCCITTCompression(tif))\n                      photometric = PHOTOMETRIC_MINISWHITE;\n                    else\n                       photometric = PHOTOMETRIC_MINISBLACK;\n                    break;\n            case 3: photometric = PHOTOMETRIC_RGB;\n                    break;\n            case 4: photometric = PHOTOMETRIC_SEPARATED;\n                    break;\n            }\n       }\n     setupPageState(tif, &pixwidth, &pixheight, &pswidth, &psheight);\n     view_width = pswidth;\n     view_height = psheight;\n     if (get_viewport (pgwidth, pgheight, pswidth, psheight, &view_width, &view_height, rotation))\n       {\n       TIFFError("get_viewport", "Unable to set image viewport");\n       return (1);\n       }\n     if (psStart(fd, npages, auto_rotate, &rotation, &scale, ox, oy,\n                pgwidth, pgheight, view_width, view_height, pswidth, psheight,\n                 left_offset, bottom_offset))\n       return (-1);\n     if (checkImage(tif))\n       {\n       tf_bytesperrow = TIFFScanlineSize(tif);\n       if ((maxPageHeight) || (maxPageWidth)  || (pgwidth != 0) || (pgheight != 0))\n         {\n        if ((maxPageHeight) || (maxPageWidth))\n           {\n          if (psMaskImage(fd, tif, rotation, center, &npages, pixwidth, pixheight,\n                          left_offset, bottom_offset, pgwidth, pgheight,\n                           pswidth, psheight, scale) < 0)\n            return (-1);\n          }\n         else\n           {\n           if (pgwidth != 0 || pgheight != 0)\n             {\n             npages++;\n             fprintf(fd, "%%%%Page: %d %d\\n", npages, npages);\n             if (!generateEPSF && ( level2 || level3 ))\n               {\n              if (psPageSize(fd, rotation, pgwidth, pgheight,\n                              view_width, view_height, pswidth, psheight))\n                return (-1);\n               }\n             fprintf(fd, "gsave\\n");\n             fprintf(fd, "100 dict begin\\n");\n             if (psScaleImage(fd, scale, rotation, center, view_width, view_height,\n                              pswidth, psheight, left_offset, bottom_offset))\n              return (-1);\n             PSpage(fd, tif, pixwidth, pixheight);\n             fprintf(fd, "end\\n");\n             fprintf(fd, "grestore\\n");\n             fprintf(fd, "showpage\\n");\n            }\n          }\n        }\n       else\n         {\n         npages++;\n         fprintf(fd, "%%%%Page: %d %d\\n", npages, npages);\n         if (!generateEPSF && ( level2 || level3 ))\n           {\n          if (psPageSize(fd, rotation, pgwidth, pgheight,\n                          view_width, view_height, pswidth, psheight))\n           return (-1);\n         }\n         fprintf(fd, "gsave\\n");\n         fprintf(fd, "100 dict begin\\n");\n        if (psRotateImage(fd, rotation, pswidth, psheight, left_offset, bottom_offset))\n           return (-1);\n         PSpage(fd, tif, pixwidth, pixheight);\n         fprintf(fd, "end\\n");\n         fprintf(fd, "grestore\\n");\n         fprintf(fd, "showpage\\n");\n         }\n       }\n  if (generateEPSF)\n    break;\n  if (auto_rotate)\n    rotation = 0.0;\n  TIFFGetFieldDefaulted(tif, TIFFTAG_SUBFILETYPE, &subfiletype);\n  } while (((subfiletype & FILETYPE_PAGE) || printAll) && TIFFReadDirectory(tif));\nreturn(npages);\n}', 'int\nTIFFReadDirectory(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFReadDirectory";\n\tTIFFDirEntry* dir;\n\tuint16 dircount;\n\tTIFFDirEntry* dp;\n\tuint16 di;\n\tconst TIFFField* fip;\n\tuint32 fii=FAILED_FII;\n        toff_t nextdiroff;\n    int bitspersample_read = FALSE;\n        int color_channels;\n\ttif->tif_diroff=tif->tif_nextdiroff;\n\tif (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff))\n\t\treturn 0;\n\t(*tif->tif_cleanup)(tif);\n\ttif->tif_curdir++;\n        nextdiroff = tif->tif_nextdiroff;\n\tdircount=TIFFFetchDirectory(tif,nextdiroff,&dir,&tif->tif_nextdiroff);\n\tif (!dircount)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t    "Failed to read directory at offset " TIFF_UINT64_FORMAT,nextdiroff);\n\t\treturn 0;\n\t}\n\tTIFFReadDirectoryCheckOrder(tif,dir,dircount);\n\t{\n\t\tTIFFDirEntry* ma;\n\t\tuint16 mb;\n\t\tfor (ma=dir, mb=0; mb<dircount; ma++, mb++)\n\t\t{\n\t\t\tTIFFDirEntry* na;\n\t\t\tuint16 nb;\n\t\t\tfor (na=ma+1, nb=mb+1; nb<dircount; na++, nb++)\n\t\t\t{\n\t\t\t\tif (ma->tdir_tag==na->tdir_tag)\n\t\t\t\t\tna->tdir_tag=IGNORE;\n\t\t\t}\n\t\t}\n\t}\n\ttif->tif_flags &= ~TIFF_BEENWRITING;\n\ttif->tif_flags &= ~TIFF_BUF4WRITE;\n\tTIFFFreeDirectory(tif);\n\tTIFFDefaultDirectory(tif);\n\tTIFFSetField(tif,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);\n\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_SAMPLESPERPIXEL);\n\tif (dp)\n\t{\n\t\tif (!TIFFFetchNormalTag(tif,dp,0))\n\t\t\tgoto bad;\n\t\tdp->tdir_tag=IGNORE;\n\t}\n\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_COMPRESSION);\n\tif (dp)\n\t{\n\t\tuint16 value;\n\t\tenum TIFFReadDirEntryErr err;\n\t\terr=TIFFReadDirEntryShort(tif,dp,&value);\n\t\tif (err==TIFFReadDirEntryErrCount)\n\t\t\terr=TIFFReadDirEntryPersampleShort(tif,dp,&value);\n\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t{\n\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,"Compression",0);\n\t\t\tgoto bad;\n\t\t}\n\t\tif (!TIFFSetField(tif,TIFFTAG_COMPRESSION,value))\n\t\t\tgoto bad;\n\t\tdp->tdir_tag=IGNORE;\n\t}\n\telse\n\t{\n\t\tif (!TIFFSetField(tif,TIFFTAG_COMPRESSION,COMPRESSION_NONE))\n\t\t\tgoto bad;\n\t}\n\tfor (di=0, dp=dir; di<dircount; di++, dp++)\n\t{\n\t\tif (dp->tdir_tag!=IGNORE)\n\t\t{\n\t\t\tTIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii);\n\t\t\tif (fii == FAILED_FII)\n\t\t\t{\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t\t    "Unknown field with tag %d (0x%x) encountered",\n\t\t\t\t    dp->tdir_tag,dp->tdir_tag);\n\t\t\t\tif (!_TIFFMergeFields(tif,\n\t\t\t\t\t_TIFFCreateAnonField(tif,\n\t\t\t\t\t\tdp->tdir_tag,\n\t\t\t\t\t\t(TIFFDataType) dp->tdir_type),\n\t\t\t\t\t1)) {\n\t\t\t\t\tTIFFWarningExt(tif->tif_clientdata,\n\t\t\t\t\t    module,\n\t\t\t\t\t    "Registering anonymous field with tag %d (0x%x) failed",\n\t\t\t\t\t    dp->tdir_tag,\n\t\t\t\t\t    dp->tdir_tag);\n\t\t\t\t\tdp->tdir_tag=IGNORE;\n\t\t\t\t} else {\n\t\t\t\t\tTIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii);\n\t\t\t\t\tassert(fii != FAILED_FII);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (dp->tdir_tag!=IGNORE)\n\t\t{\n\t\t\tfip=tif->tif_fields[fii];\n\t\t\tif (fip->field_bit==FIELD_IGNORE)\n\t\t\t\tdp->tdir_tag=IGNORE;\n\t\t\telse\n\t\t\t{\n\t\t\t\tswitch (dp->tdir_tag)\n\t\t\t\t{\n\t\t\t\t\tcase TIFFTAG_STRIPOFFSETS:\n\t\t\t\t\tcase TIFFTAG_STRIPBYTECOUNTS:\n\t\t\t\t\tcase TIFFTAG_TILEOFFSETS:\n\t\t\t\t\tcase TIFFTAG_TILEBYTECOUNTS:\n\t\t\t\t\t\tTIFFSetFieldBit(tif,fip->field_bit);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase TIFFTAG_IMAGEWIDTH:\n\t\t\t\t\tcase TIFFTAG_IMAGELENGTH:\n\t\t\t\t\tcase TIFFTAG_IMAGEDEPTH:\n\t\t\t\t\tcase TIFFTAG_TILELENGTH:\n\t\t\t\t\tcase TIFFTAG_TILEWIDTH:\n\t\t\t\t\tcase TIFFTAG_TILEDEPTH:\n\t\t\t\t\tcase TIFFTAG_PLANARCONFIG:\n\t\t\t\t\tcase TIFFTAG_ROWSPERSTRIP:\n\t\t\t\t\tcase TIFFTAG_EXTRASAMPLES:\n\t\t\t\t\t\tif (!TIFFFetchNormalTag(tif,dp,0))\n\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\tdp->tdir_tag=IGNORE;\n\t\t\t\t\t\tbreak;\n                                        default:\n                                            if( !_TIFFCheckFieldIsValidForCodec(tif, dp->tdir_tag) )\n                                                dp->tdir_tag=IGNORE;\n                                            break;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif ((tif->tif_dir.td_compression==COMPRESSION_OJPEG)&&\n\t    (tif->tif_dir.td_planarconfig==PLANARCONFIG_SEPARATE))\n\t{\n        if (!_TIFFFillStriles(tif))\n            goto bad;\n\t\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_STRIPOFFSETS);\n\t\tif ((dp!=0)&&(dp->tdir_count==1))\n\t\t{\n\t\t\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,\n\t\t\t    TIFFTAG_STRIPBYTECOUNTS);\n\t\t\tif ((dp!=0)&&(dp->tdir_count==1))\n\t\t\t{\n\t\t\t\ttif->tif_dir.td_planarconfig=PLANARCONFIG_CONTIG;\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t    "Planarconfig tag value assumed incorrect, "\n\t\t\t\t    "assuming data is contig instead of chunky");\n\t\t\t}\n\t\t}\n\t}\n\tif (!TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS))\n\t{\n\t\tMissingRequired(tif,"ImageLength");\n\t\tgoto bad;\n\t}\n\tif (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) {\n\t\ttif->tif_dir.td_nstrips = TIFFNumberOfStrips(tif);\n\t\ttif->tif_dir.td_tilewidth = tif->tif_dir.td_imagewidth;\n\t\ttif->tif_dir.td_tilelength = tif->tif_dir.td_rowsperstrip;\n\t\ttif->tif_dir.td_tiledepth = tif->tif_dir.td_imagedepth;\n\t\ttif->tif_flags &= ~TIFF_ISTILED;\n\t} else {\n\t\ttif->tif_dir.td_nstrips = TIFFNumberOfTiles(tif);\n\t\ttif->tif_flags |= TIFF_ISTILED;\n\t}\n\tif (!tif->tif_dir.td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t    "Cannot handle zero number of %s",\n\t\t    isTiled(tif) ? "tiles" : "strips");\n\t\tgoto bad;\n\t}\n\ttif->tif_dir.td_stripsperimage = tif->tif_dir.td_nstrips;\n\tif (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\ttif->tif_dir.td_stripsperimage /= tif->tif_dir.td_samplesperpixel;\n\tif (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) {\n#ifdef OJPEG_SUPPORT\n\t\tif ((tif->tif_dir.td_compression==COMPRESSION_OJPEG) &&\n\t\t    (isTiled(tif)==0) &&\n\t\t    (tif->tif_dir.td_nstrips==1)) {\n\t\t\tTIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);\n\t\t} else\n#endif\n        {\n\t\t\tMissingRequired(tif,\n\t\t\t\tisTiled(tif) ? "TileOffsets" : "StripOffsets");\n\t\t\tgoto bad;\n\t\t}\n\t}\n\tfor (di=0, dp=dir; di<dircount; di++, dp++)\n\t{\n\t\tswitch (dp->tdir_tag)\n\t\t{\n\t\t\tcase IGNORE:\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_MINSAMPLEVALUE:\n\t\t\tcase TIFFTAG_MAXSAMPLEVALUE:\n\t\t\tcase TIFFTAG_BITSPERSAMPLE:\n\t\t\tcase TIFFTAG_DATATYPE:\n\t\t\tcase TIFFTAG_SAMPLEFORMAT:\n\t\t\t\t{\n\t\t\t\t\tuint16 value;\n\t\t\t\t\tenum TIFFReadDirEntryErr err;\n\t\t\t\t\terr=TIFFReadDirEntryShort(tif,dp,&value);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrCount)\n\t\t\t\t\t\terr=TIFFReadDirEntryPersampleShort(tif,dp,&value);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tfip = TIFFFieldWithTag(tif,dp->tdir_tag);\n\t\t\t\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0);\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t}\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,value))\n\t\t\t\t\t\tgoto bad;\n                    if( dp->tdir_tag == TIFFTAG_BITSPERSAMPLE )\n                        bitspersample_read = TRUE;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_SMINSAMPLEVALUE:\n\t\t\tcase TIFFTAG_SMAXSAMPLEVALUE:\n\t\t\t\t{\n\t\t\t\t\tdouble *data = NULL;\n\t\t\t\t\tenum TIFFReadDirEntryErr err;\n\t\t\t\t\tuint32 saved_flags;\n\t\t\t\t\tint m;\n\t\t\t\t\tif (dp->tdir_count != (uint64)tif->tif_dir.td_samplesperpixel)\n\t\t\t\t\t\terr = TIFFReadDirEntryErrCount;\n\t\t\t\t\telse\n\t\t\t\t\t\terr = TIFFReadDirEntryDoubleArray(tif, dp, &data);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tfip = TIFFFieldWithTag(tif,dp->tdir_tag);\n\t\t\t\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0);\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t}\n\t\t\t\t\tsaved_flags = tif->tif_flags;\n\t\t\t\t\ttif->tif_flags |= TIFF_PERSAMPLE;\n\t\t\t\t\tm = TIFFSetField(tif,dp->tdir_tag,data);\n\t\t\t\t\ttif->tif_flags = saved_flags;\n\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_STRIPOFFSETS:\n\t\t\tcase TIFFTAG_TILEOFFSETS:\n                                _TIFFmemcpy( &(tif->tif_dir.td_stripoffset_entry),\n                                             dp, sizeof(TIFFDirEntry) );\n                                if( !(tif->tif_flags&TIFF_DEFERSTRILELOAD) )\n                                {\n                                    if( tif->tif_dir.td_stripoffset_p != NULL )\n                                    {\n                                        TIFFErrorExt(tif->tif_clientdata, module,\n                                            "tif->tif_dir.td_stripoffset is "\n                                            "already allocated. Likely duplicated "\n                                            "StripOffsets/TileOffsets tag");\n                                        goto bad;\n                                    }\n                                    if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripoffset_p))\n                                            goto bad;\n                                }\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_STRIPBYTECOUNTS:\n\t\t\tcase TIFFTAG_TILEBYTECOUNTS:\n                                _TIFFmemcpy( &(tif->tif_dir.td_stripbytecount_entry),\n                                             dp, sizeof(TIFFDirEntry) );\n                                if( !(tif->tif_flags&TIFF_DEFERSTRILELOAD) )\n                                {\n                                    if( tif->tif_dir.td_stripbytecount_p != NULL )\n                                    {\n                                        TIFFErrorExt(tif->tif_clientdata, module,\n                                            "tif->tif_dir.td_stripbytecount is "\n                                            "already allocated. Likely duplicated "\n                                            "StripByteCounts/TileByteCounts tag");\n                                        goto bad;\n                                    }\n                                    if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripbytecount_p))\n                                            goto bad;\n                                }\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_COLORMAP:\n\t\t\tcase TIFFTAG_TRANSFERFUNCTION:\n\t\t\t\t{\n\t\t\t\t\tenum TIFFReadDirEntryErr err;\n\t\t\t\t\tuint32 countpersample;\n\t\t\t\t\tuint32 countrequired;\n\t\t\t\t\tuint32 incrementpersample;\n\t\t\t\t\tuint16* value=NULL;\n                    if( !bitspersample_read )\n                    {\n                        fip = TIFFFieldWithTag(tif,dp->tdir_tag);\n                        TIFFWarningExt(tif->tif_clientdata,module,\n                                       "Ignoring %s since BitsPerSample tag not found",\n                                       fip ? fip->field_name : "unknown tagname");\n                        continue;\n                    }\n\t\t\t\t\tif (tif->tif_dir.td_bitspersample > 24)\n\t\t\t\t\t{\n\t\t\t\t\t    fip = TIFFFieldWithTag(tif,dp->tdir_tag);\n\t\t\t\t\t    TIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t\t\t"Ignoring %s because BitsPerSample=%d>24",\n\t\t\t\t\t\tfip ? fip->field_name : "unknown tagname",\n\t\t\t\t\t\ttif->tif_dir.td_bitspersample);\n\t\t\t\t\t    continue;\n\t\t\t\t\t}\n\t\t\t\t\tcountpersample=(1U<<tif->tif_dir.td_bitspersample);\n\t\t\t\t\tif ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCTION)&&(dp->tdir_count==(uint64)countpersample))\n\t\t\t\t\t{\n\t\t\t\t\t\tcountrequired=countpersample;\n\t\t\t\t\t\tincrementpersample=0;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tcountrequired=3*countpersample;\n\t\t\t\t\t\tincrementpersample=countpersample;\n\t\t\t\t\t}\n\t\t\t\t\tif (dp->tdir_count!=(uint64)countrequired)\n\t\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\t\telse\n\t\t\t\t\t\terr=TIFFReadDirEntryShortArray(tif,dp,&value);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n                    {\n\t\t\t\t\t\tfip = TIFFFieldWithTag(tif,dp->tdir_tag);\n\t\t\t\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",1);\n                    }\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tTIFFSetField(tif,dp->tdir_tag,value,value+incrementpersample,value+2*incrementpersample);\n\t\t\t\t\t\t_TIFFfree(value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_OSUBFILETYPE:\n\t\t\t\t{\n\t\t\t\t\tuint16 valueo;\n\t\t\t\t\tuint32 value;\n\t\t\t\t\tif (TIFFReadDirEntryShort(tif,dp,&valueo)==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tswitch (valueo)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcase OFILETYPE_REDUCEDIMAGE: value=FILETYPE_REDUCEDIMAGE; break;\n\t\t\t\t\t\t\tcase OFILETYPE_PAGE: value=FILETYPE_PAGE; break;\n\t\t\t\t\t\t\tdefault: value=0; break;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (value!=0)\n\t\t\t\t\t\t\tTIFFSetField(tif,TIFFTAG_SUBFILETYPE,value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t(void) TIFFFetchNormalTag(tif, dp, TRUE);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tif (tif->tif_dir.td_compression==COMPRESSION_OJPEG)\n\t{\n\t\tif (!TIFFFieldSet(tif,FIELD_PHOTOMETRIC))\n\t\t{\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t    "Photometric tag is missing, assuming data is YCbCr");\n\t\t\tif (!TIFFSetField(tif,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_YCBCR))\n\t\t\t\tgoto bad;\n\t\t}\n\t\telse if (tif->tif_dir.td_photometric==PHOTOMETRIC_RGB)\n\t\t{\n\t\t\ttif->tif_dir.td_photometric=PHOTOMETRIC_YCBCR;\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t    "Photometric tag value assumed incorrect, "\n\t\t\t    "assuming data is YCbCr instead of RGB");\n\t\t}\n\t\tif (!TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))\n\t\t{\n\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t    "BitsPerSample tag is missing, assuming 8 bits per sample");\n\t\t\tif (!TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,8))\n\t\t\t\tgoto bad;\n\t\t}\n\t\tif (!TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))\n\t\t{\n\t\t\tif (tif->tif_dir.td_photometric==PHOTOMETRIC_RGB)\n\t\t\t{\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t    "SamplesPerPixel tag is missing, "\n\t\t\t\t    "assuming correct SamplesPerPixel value is 3");\n\t\t\t\tif (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,3))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR)\n\t\t\t{\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t    "SamplesPerPixel tag is missing, "\n\t\t\t\t    "applying correct SamplesPerPixel value of 3");\n\t\t\t\tif (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,3))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\telse if ((tif->tif_dir.td_photometric==PHOTOMETRIC_MINISWHITE)\n\t\t\t\t || (tif->tif_dir.td_photometric==PHOTOMETRIC_MINISBLACK))\n\t\t\t{\n\t\t\t\tif (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,1))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t}\n\t}\n        color_channels = _TIFFGetMaxColorChannels(tif->tif_dir.td_photometric);\n        if (color_channels && tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples > color_channels) {\n                uint16 old_extrasamples;\n                uint16 *new_sampleinfo;\n                TIFFWarningExt(tif->tif_clientdata,module, "Sum of Photometric type-related "\n                    "color channels and ExtraSamples doesn\'t match SamplesPerPixel. "\n                    "Defining non-color channels as ExtraSamples.");\n                old_extrasamples = tif->tif_dir.td_extrasamples;\n                tif->tif_dir.td_extrasamples = (uint16) (tif->tif_dir.td_samplesperpixel - color_channels);\n                new_sampleinfo = (uint16*) _TIFFcalloc(tif->tif_dir.td_extrasamples, sizeof(uint16));\n                if (!new_sampleinfo) {\n                    TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate memory for "\n                                "temporary new sampleinfo array (%d 16 bit elements)",\n                                tif->tif_dir.td_extrasamples);\n                    goto bad;\n                }\n                memcpy(new_sampleinfo, tif->tif_dir.td_sampleinfo, old_extrasamples * sizeof(uint16));\n                _TIFFsetShortArray(&tif->tif_dir.td_sampleinfo, new_sampleinfo, tif->tif_dir.td_extrasamples);\n                _TIFFfree(new_sampleinfo);\n        }\n\tif (tif->tif_dir.td_photometric == PHOTOMETRIC_PALETTE &&\n\t    !TIFFFieldSet(tif, FIELD_COLORMAP)) {\n\t\tif ( tif->tif_dir.td_bitspersample>=8 && tif->tif_dir.td_samplesperpixel==3)\n\t\t\ttif->tif_dir.td_photometric = PHOTOMETRIC_RGB;\n\t\telse if (tif->tif_dir.td_bitspersample>=8)\n\t\t\ttif->tif_dir.td_photometric = PHOTOMETRIC_MINISBLACK;\n\t\telse {\n\t\t\tMissingRequired(tif, "Colormap");\n\t\t\tgoto bad;\n\t\t}\n\t}\n\tif (tif->tif_dir.td_compression!=COMPRESSION_OJPEG)\n\t{\n\t\tif (!TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS)) {\n\t\t\tif ((tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG &&\n\t\t\t    tif->tif_dir.td_nstrips > 1) ||\n\t\t\t    (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE &&\n\t\t\t     tif->tif_dir.td_nstrips != (uint32)tif->tif_dir.td_samplesperpixel)) {\n\t\t\t    MissingRequired(tif, "StripByteCounts");\n\t\t\t    goto bad;\n\t\t\t}\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t\t"TIFF directory is missing required "\n\t\t\t\t"\\"StripByteCounts\\" field, calculating from imagelength");\n\t\t\tif (EstimateStripByteCounts(tif, dir, dircount) < 0)\n\t\t\t    goto bad;\n\t\t} else if (tif->tif_dir.td_nstrips == 1\n                           && !(tif->tif_flags&TIFF_ISTILED)\n\t\t\t   && ByteCountLooksBad(tif)) {\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t    "Bogus \\"StripByteCounts\\" field, ignoring and calculating from imagelength");\n\t\t\tif(EstimateStripByteCounts(tif, dir, dircount) < 0)\n\t\t\t    goto bad;\n\t\t} else if (!(tif->tif_flags&TIFF_DEFERSTRILELOAD)\n\t\t\t   && tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG\n\t\t\t   && tif->tif_dir.td_nstrips > 2\n\t\t\t   && tif->tif_dir.td_compression == COMPRESSION_NONE\n\t\t\t   && TIFFGetStrileByteCount(tif, 0) != TIFFGetStrileByteCount(tif, 1)\n\t\t\t   && TIFFGetStrileByteCount(tif, 0) != 0\n\t\t\t   && TIFFGetStrileByteCount(tif, 1) != 0 ) {\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t    "Wrong \\"StripByteCounts\\" field, ignoring and calculating from imagelength");\n\t\t\tif (EstimateStripByteCounts(tif, dir, dircount) < 0)\n\t\t\t    goto bad;\n\t\t}\n\t}\n\tif (dir)\n\t{\n\t\t_TIFFfree(dir);\n\t\tdir=NULL;\n\t}\n\tif (!TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE))\n\t{\n\t\tif (tif->tif_dir.td_bitspersample>=16)\n\t\t\ttif->tif_dir.td_maxsamplevalue=0xFFFF;\n\t\telse\n\t\t\ttif->tif_dir.td_maxsamplevalue = (uint16)((1L<<tif->tif_dir.td_bitspersample)-1);\n\t}\n#ifdef STRIPBYTECOUNTSORTED_UNUSED\n\tif (!(tif->tif_flags&TIFF_DEFERSTRILELOAD) && tif->tif_dir.td_nstrips > 1) {\n\t\tuint32 strip;\n\t\ttif->tif_dir.td_stripbytecountsorted = 1;\n\t\tfor (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) {\n\t\t\tif (TIFFGetStrileOffset(tif, strip - 1) >\n\t\t\t    TIFFGetStrileOffset(tif, strip)) {\n\t\t\t\ttif->tif_dir.td_stripbytecountsorted = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\t(*tif->tif_fixuptags)(tif);\n\tif ((tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&&\n\t    (tif->tif_dir.td_nstrips==1)&&\n\t    (tif->tif_dir.td_compression==COMPRESSION_NONE)&&\n\t    ((tif->tif_flags&(TIFF_STRIPCHOP|TIFF_ISTILED))==TIFF_STRIPCHOP))\n        {\n            ChopUpSingleUncompressedStrip(tif);\n        }\n        if( tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG &&\n            tif->tif_dir.td_compression == COMPRESSION_NONE &&\n            (tif->tif_flags&(TIFF_STRIPCHOP|TIFF_ISTILED)) == TIFF_STRIPCHOP &&\n            TIFFStripSize64(tif) > 0x7FFFFFFFUL )\n        {\n            TryChopUpUncompressedBigTiff(tif);\n        }\n\ttif->tif_flags &= ~TIFF_DIRTYDIRECT;\n\ttif->tif_flags &= ~TIFF_DIRTYSTRIP;\n\ttif->tif_row = (uint32) -1;\n\ttif->tif_curstrip = (uint32) -1;\n\ttif->tif_col = (uint32) -1;\n\ttif->tif_curtile = (uint32) -1;\n\ttif->tif_tilesize = (tmsize_t) -1;\n\ttif->tif_scanlinesize = TIFFScanlineSize(tif);\n\tif (!tif->tif_scanlinesize) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t    "Cannot handle zero scanline size");\n\t\treturn (0);\n\t}\n\tif (isTiled(tif)) {\n\t\ttif->tif_tilesize = TIFFTileSize(tif);\n\t\tif (!tif->tif_tilesize) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t     "Cannot handle zero tile size");\n\t\t\treturn (0);\n\t\t}\n\t} else {\n\t\tif (!TIFFStripSize(tif)) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t    "Cannot handle zero strip size");\n\t\t\treturn (0);\n\t\t}\n\t}\n\treturn (1);\nbad:\n\tif (dir)\n\t\t_TIFFfree(dir);\n\treturn (0);\n}', 'static int\nTIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, uint32 nstrips, uint64** lpp)\n{\n\tstatic const char module[] = "TIFFFetchStripThing";\n\tenum TIFFReadDirEntryErr err;\n\tuint64* data;\n\terr=TIFFReadDirEntryLong8ArrayWithLimit(tif,dir,&data,nstrips);\n\tif (err!=TIFFReadDirEntryErrOk)\n\t{\n\t\tconst TIFFField* fip = TIFFFieldWithTag(tif,dir->tdir_tag);\n\t\tTIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0);\n\t\treturn(0);\n\t}\n\tif (dir->tdir_count<(uint64)nstrips)\n\t{\n\t\tuint64* resizeddata;\n\t\tconst TIFFField* fip = TIFFFieldWithTag(tif,dir->tdir_tag);\n\t\tconst char* pszMax = getenv("LIBTIFF_STRILE_ARRAY_MAX_RESIZE_COUNT");\n\t\tuint32 max_nstrips = 1000000;\n\t\tif( pszMax )\n\t\t\tmax_nstrips = (uint32) atoi(pszMax);\n\t\tTIFFReadDirEntryOutputErr(tif,TIFFReadDirEntryErrCount,\n\t\t            module,\n\t\t            fip ? fip->field_name : "unknown tagname",\n\t\t            ( nstrips <= max_nstrips ) );\n\t\tif( nstrips > max_nstrips )\n\t\t{\n\t\t\t_TIFFfree(data);\n\t\t\treturn(0);\n\t\t}\n\t\tresizeddata=(uint64*)_TIFFCheckMalloc(tif,nstrips,sizeof(uint64),"for strip array");\n\t\tif (resizeddata==0) {\n\t\t\t_TIFFfree(data);\n\t\t\treturn(0);\n\t\t}\n                _TIFFmemcpy(resizeddata,data,(uint32)dir->tdir_count*sizeof(uint64));\n                _TIFFmemset(resizeddata+(uint32)dir->tdir_count,0,(nstrips-(uint32)dir->tdir_count)*sizeof(uint64));\n\t\t_TIFFfree(data);\n\t\tdata=resizeddata;\n\t}\n\t*lpp=data;\n\treturn(1);\n}', 'static void TryChopUpUncompressedBigTiff( TIFF* tif )\n{\n    TIFFDirectory *td = &tif->tif_dir;\n    uint32 rowblock;\n    uint64 rowblockbytes;\n    uint32 i;\n    uint64 stripsize;\n    uint32 rowblocksperstrip;\n    uint32 rowsperstrip;\n    uint64 stripbytes;\n    uint32 nstrips;\n    stripsize = TIFFStripSize64(tif);\n    assert( tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG );\n    assert( tif->tif_dir.td_compression == COMPRESSION_NONE );\n    assert( (tif->tif_flags&(TIFF_STRIPCHOP|TIFF_ISTILED)) == TIFF_STRIPCHOP );\n    assert( stripsize > 0x7FFFFFFFUL );\n    if( TIFFGetStrileByteCount(tif, 0) == 0 && tif->tif_mode != O_RDONLY )\n        return;\n    if ((td->td_photometric == PHOTOMETRIC_YCBCR)&&\n        (!isUpSampled(tif)))\n        rowblock = td->td_ycbcrsubsampling[1];\n    else\n        rowblock = 1;\n    rowblockbytes = TIFFVStripSize64(tif, rowblock);\n    if( rowblockbytes == 0 || rowblockbytes > 0x7FFFFFFFUL )\n    {\n        return;\n    }\n    for( i = 0; i < td->td_nstrips; i++ )\n    {\n        if( i == td->td_nstrips - 1 )\n        {\n            if( TIFFGetStrileByteCount(tif, i) < TIFFVStripSize64(\n                    tif, td->td_imagelength - i * td->td_rowsperstrip ) )\n            {\n                return;\n            }\n        }\n        else\n        {\n            if( TIFFGetStrileByteCount(tif, i) != stripsize )\n            {\n                return;\n            }\n            if( i > 0 && TIFFGetStrileOffset(tif, i) !=\n                    TIFFGetStrileOffset(tif, i-1) + TIFFGetStrileByteCount(tif, i-1) )\n            {\n                return;\n            }\n        }\n    }\n    rowblocksperstrip = (uint32) (512 * 1024 * 1024 / rowblockbytes);\n    if( rowblocksperstrip == 0 )\n        rowblocksperstrip = 1;\n    rowsperstrip = rowblocksperstrip * rowblock;\n    stripbytes = rowblocksperstrip * rowblockbytes;\n    assert( stripbytes <= 0x7FFFFFFFUL );\n    nstrips = TIFFhowmany_32(td->td_imagelength, rowsperstrip);\n    if( nstrips == 0 )\n        return;\n    if( tif->tif_mode == O_RDONLY &&\n        nstrips > 1000000 &&\n        (TIFFGetStrileOffset(tif, td->td_nstrips-1) > TIFFGetFileSize(tif) ||\n         TIFFGetStrileOffset(tif, td->td_nstrips-1) +\n         TIFFGetStrileByteCount(tif, td->td_nstrips-1) > TIFFGetFileSize(tif)) )\n    {\n        return;\n    }\n    allocChoppedUpStripArrays(tif, nstrips, stripbytes, rowsperstrip);\n}', 'uint64 TIFFGetStrileOffset(TIFF *tif, uint32 strile)\n{\n    return TIFFGetStrileOffsetWithErr(tif, strile, NULL);\n}', 'uint64 TIFFGetStrileOffsetWithErr(TIFF *tif, uint32 strile, int *pbErr)\n{\n    TIFFDirectory *td = &tif->tif_dir;\n    return _TIFFGetStrileOffsetOrByteCountValue(tif, strile,\n                               &(td->td_stripoffset_entry),\n                               &(td->td_stripoffset_p), pbErr);\n}', 'static uint64 _TIFFGetStrileOffsetOrByteCountValue(TIFF *tif, uint32 strile,\n                                                   TIFFDirEntry* dirent,\n                                                   uint64** parray,\n                                                   int *pbErr)\n{\n    TIFFDirectory *td = &tif->tif_dir;\n    if( pbErr )\n        *pbErr = 0;\n    if( tif->tif_flags&TIFF_DEFERSTRILELOAD )\n    {\n        if( !(tif->tif_flags&TIFF_LAZYSTRILELOAD) ||\n            dirent->tdir_count <= 4 )\n        {\n            if( !_TIFFFillStriles(tif) )\n            {\n                if( pbErr )\n                    *pbErr = 1;\n                return 0;\n            }\n        }\n        else\n        {\n             if( !_TIFFFetchStrileValue(tif, strile, dirent, parray) )\n             {\n                if( pbErr )\n                    *pbErr = 1;\n                 return 0;\n             }\n        }\n    }\n    if( *parray == NULL || strile >= td->td_nstrips )\n    {\n        if( pbErr )\n            *pbErr = 1;\n        return 0;\n    }\n    return (*parray)[strile];\n}', 'static int _TIFFFetchStrileValue(TIFF* tif,\n                                 uint32 strile,\n                                 TIFFDirEntry* dirent,\n                                 uint64** parray)\n{\n    static const char module[] = "_TIFFFetchStrileValue";\n    TIFFDirectory *td = &tif->tif_dir;\n    if( strile >= dirent->tdir_count )\n    {\n        return 0;\n    }\n    if( strile >= td->td_stripoffsetbyteallocsize )\n    {\n        uint32 nStripArrayAllocBefore = td->td_stripoffsetbyteallocsize;\n        uint32 nStripArrayAllocNew;\n        uint64 nArraySize64;\n        size_t nArraySize;\n        uint64* offsetArray;\n        uint64* bytecountArray;\n        if( strile > 1000000 )\n        {\n            uint64 filesize = TIFFGetFileSize(tif);\n            if( strile > filesize / sizeof(uint32) )\n            {\n                TIFFErrorExt(tif->tif_clientdata, module, "File too short");\n                return 0;\n            }\n        }\n        if( td->td_stripoffsetbyteallocsize == 0 &&\n            td->td_nstrips < 1024 * 1024 )\n        {\n            nStripArrayAllocNew = td->td_nstrips;\n        }\n        else\n        {\n#define TIFF_MAX(a,b) (((a)>(b)) ? (a) : (b))\n#define TIFF_MIN(a,b) (((a)<(b)) ? (a) : (b))\n            nStripArrayAllocNew = TIFF_MAX(strile + 1, 1024U * 512U );\n            if( nStripArrayAllocNew < 0xFFFFFFFFU / 2  )\n                nStripArrayAllocNew *= 2;\n            nStripArrayAllocNew = TIFF_MIN(nStripArrayAllocNew, td->td_nstrips);\n        }\n        assert( strile < nStripArrayAllocNew );\n        nArraySize64 = (uint64)sizeof(uint64) * nStripArrayAllocNew;\n        nArraySize = (size_t)(nArraySize64);\n#if SIZEOF_SIZE_T == 4\n        if( nArraySize != nArraySize64 )\n        {\n            TIFFErrorExt(tif->tif_clientdata, module,\n                        "Cannot allocate strip offset and bytecount arrays");\n            return 0;\n        }\n#endif\n        offsetArray = (uint64*)(\n            _TIFFrealloc( td->td_stripoffset_p, nArraySize ) );\n        bytecountArray = (uint64*)(\n            _TIFFrealloc( td->td_stripbytecount_p, nArraySize ) );\n        if( offsetArray )\n            td->td_stripoffset_p = offsetArray;\n        if( bytecountArray )\n            td->td_stripbytecount_p = bytecountArray;\n        if( offsetArray && bytecountArray )\n        {\n            td->td_stripoffsetbyteallocsize = nStripArrayAllocNew;\n            memset(td->td_stripoffset_p + nStripArrayAllocBefore,\n                0xFF,\n                (td->td_stripoffsetbyteallocsize - nStripArrayAllocBefore) * sizeof(uint64) );\n            memset(td->td_stripbytecount_p + nStripArrayAllocBefore,\n                0xFF,\n                (td->td_stripoffsetbyteallocsize - nStripArrayAllocBefore) * sizeof(uint64) );\n        }\n        else\n        {\n            TIFFErrorExt(tif->tif_clientdata, module,\n                        "Cannot allocate strip offset and bytecount arrays");\n            _TIFFfree(td->td_stripoffset_p);\n            td->td_stripoffset_p = NULL;\n            _TIFFfree(td->td_stripbytecount_p);\n            td->td_stripbytecount_p = NULL;\n            td->td_stripoffsetbyteallocsize = 0;\n        }\n    }\n    if( *parray == NULL || strile >= td->td_stripoffsetbyteallocsize )\n        return 0;\n    if( ~((*parray)[strile]) == 0 )\n    {\n        if( !_TIFFPartialReadStripArray( tif, dirent, strile, *parray ) )\n        {\n            (*parray)[strile] = 0;\n            return 0;\n        }\n    }\n    return 1;\n}']