tools/tiffcrop.c:6788: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned32 by call to `writeCroppedImage`.

tools/tiffcrop.c:6752:1: Parameter `(*out)->tif_dir.td_rowsperstrip`
6750.   } /* end extractImageSection */
6751. 
6752. static int 
      ^
6753. writeSelections(TIFF *in, TIFF **out, struct crop_mask *crop, 
6754.                 struct image_data *image, struct dump_opts *dump,

tools/tiffcrop.c:6782:14: Call
6780.     case ONE_FILE_SEPARATED: /* Regions as separated images */
6781.          autoindex = 0;
6782.          if (update_output_file (out, mp, autoindex, filename, page))
                   ^
6783.            return (1);
6784.          page_count = crop->selections * total_pages;

tools/tiffcrop.c:2042:1: Parameter `(*tiffout)->tif_dir.td_rowsperstrip`
  2040.  * so TIFFTAG PAGENUM will be correct in image.
  2041.  */
  2042. static int 
        ^
  2043. update_output_file (TIFF **tiffout, char *mode, int autoindex,
  2044.                     char *outname, unsigned int *page)

tools/tiffcrop.c:6788:16: Call
6786.            {
6787.            crop_buff = seg_buffs[i].buffer;
6788.            if (writeCroppedImage(in, *out, image, dump,
                     ^
6789.                                  crop->regionlist[i].width, 
6790.                                  crop->regionlist[i].length, 

tools/tiffcrop.c:7594:1: Parameter `out->tif_dir.td_rowsperstrip`
  7592.  * then passed in as an argument.
  7593.  */
  7594. static int  
        ^
  7595. writeCroppedImage(TIFF *in, TIFF *out, struct image_data *image, 
  7596.                   struct dump_opts *dump, uint32 width, uint32 length, 

tools/tiffcrop.c:7855:11: Call
  7853.     else
  7854.       {
  7855.       if (writeBufferToSeparateStrips(out, crop_buff, length, width, spp, dump))
                  ^
  7856.         TIFFError("","Unable to write separate strip data for page %d", pagenum);
  7857.       }

tools/tiffcrop.c:1129:1: Parameter `out->tif_dir.td_rowsperstrip`
    1127.  * before any strips or tiles of a different plane are stored.
    1128.  */
    1129. static int 
          ^
    1130. writeBufferToSeparateStrips (TIFF* out, uint8* buf, 
    1131. 			     uint32 length, uint32 width, uint16 spp,

tools/tiffcrop.c:1178:11: Call
    1176. 	}
    1177. 
    1178.       if (TIFFWriteEncodedStrip(out, strip++, obuf, stripsize) < 0)
                    ^
    1179.         {
    1180. 	TIFFError(TIFFFileName(out), "Error, can't write strip %u", strip - 1);

libtiff/tif_write.c:183:1: <LHS trace>
181.  * NB: Image length must be setup before writing.
182.  */
183. tmsize_t
     ^
184. TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
185. {

libtiff/tif_write.c:183:1: Parameter `tif->tif_dir.td_rowsperstrip`
      181.  * NB: Image length must be setup before writing.
      182.  */
      183. tmsize_t
           ^
      184. TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
      185. {

libtiff/tif_write.c:210:7: Binary operation: ([0, +oo] - 1):unsigned32 by call to `writeCroppedImage` 
      208. 			return ((tmsize_t) -1);
      209. 		td->td_stripsperimage =
      210. 		    TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);  
                 ^
      211. 	}
      212. 	/*

tmsize_t
TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
{
	static const char module[] = "TIFFWriteEncodedStrip";
	TIFFDirectory *td = &tif->tif_dir;
	uint16 sample;
	if (!WRITECHECKSTRIPS(tif, module))
		return ((tmsize_t) -1);
	if (strip >= td->td_nstrips) {
		if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
			TIFFErrorExt(tif->tif_clientdata, module,
			    "Can not grow image by strips when using separate planes");
			return ((tmsize_t) -1);
		}
		if (!TIFFGrowStrips(tif, 1, module))
			return ((tmsize_t) -1);
		td->td_stripsperimage =
		    TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);
	}
	if (!BUFFERCHECK(tif))
		return ((tmsize_t) -1);
        tif->tif_flags |= TIFF_BUF4WRITE;
	tif->tif_curstrip = strip;
	tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;
	if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
		if (!(*tif->tif_setupencode)(tif))
			return ((tmsize_t) -1);
		tif->tif_flags |= TIFF_CODERSETUP;
	}
	if( td->td_stripbytecount[strip] > 0 )
        {
            if( tif->tif_rawdatasize <= (tmsize_t)td->td_stripbytecount[strip] )
            {
                if( !(TIFFWriteBufferSetup(tif, NULL,
                    (tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[strip] + 1), 1024))) )
                    return ((tmsize_t)(-1));
            }
            tif->tif_curoff = 0;
        }
    tif->tif_rawcc = 0;
    tif->tif_rawcp = tif->tif_rawdata;
	tif->tif_flags &= ~TIFF_POSTENCODE;
	sample = (uint16)(strip / td->td_stripsperimage);
	if (!(*tif->tif_preencode)(tif, sample))
		return ((tmsize_t) -1);
	tif->tif_postdecode( tif, (uint8*) data, cc );
	if (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample))
		return (0);
	if (!(*tif->tif_postencode)(tif))
		return ((tmsize_t) -1);
	if (!isFillOrder(tif, td->td_fillorder) &&
	    (tif->tif_flags & TIFF_NOBITREV) == 0)
		TIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);
	if (tif->tif_rawcc > 0 &&
	    !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))
		return ((tmsize_t) -1);
	tif->tif_rawcc = 0;
	tif->tif_rawcp = tif->tif_rawdata;
	return (cc);
}
['static int\nwriteSelections(TIFF *in, TIFF **out, struct crop_mask *crop,\n                struct image_data *image, struct dump_opts *dump,\n                struct buffinfo seg_buffs[], char *mp, char *filename,\n                unsigned int *page, unsigned int total_pages)\n  {\n  int i, page_count;\n  int autoindex = 0;\n  unsigned char *crop_buff = NULL;\n  switch (crop->exp_mode)\n    {\n    case ONE_FILE_COMPOSITE:\n         autoindex = 0;\n         crop_buff = seg_buffs[0].buffer;\n         if (update_output_file (out, mp, autoindex, filename, page))\n           return (1);\n         page_count = total_pages;\n         if (writeCroppedImage(in, *out, image, dump,\n                               crop->combined_width,\n                               crop->combined_length,\n                               crop_buff, *page, total_pages))\n            {\n             TIFFError("writeRegions", "Unable to write new image");\n             return (-1);\n             }\n\t break;\n    case ONE_FILE_SEPARATED:\n         autoindex = 0;\n         if (update_output_file (out, mp, autoindex, filename, page))\n           return (1);\n         page_count = crop->selections * total_pages;\n         for (i = 0; i < crop->selections; i++)\n           {\n           crop_buff = seg_buffs[i].buffer;\n           if (writeCroppedImage(in, *out, image, dump,\n                                 crop->regionlist[i].width,\n                                 crop->regionlist[i].length,\n                                 crop_buff, *page, page_count))\n             {\n             TIFFError("writeRegions", "Unable to write new image");\n             return (-1);\n             }\n\t   }\n         break;\n    case FILE_PER_IMAGE_COMPOSITE:\n         autoindex = 1;\n         if (update_output_file (out, mp, autoindex, filename, page))\n           return (1);\n         crop_buff = seg_buffs[0].buffer;\n         if (writeCroppedImage(in, *out, image, dump,\n                               crop->combined_width,\n                               crop->combined_length,\n                               crop_buff, *page, total_pages))\n           {\n           TIFFError("writeRegions", "Unable to write new image");\n           return (-1);\n           }\n         break;\n    case FILE_PER_IMAGE_SEPARATED:\n         autoindex = 1;\n         page_count = crop->selections;\n         if (update_output_file (out, mp, autoindex, filename, page))\n           return (1);\n         for (i = 0; i < crop->selections; i++)\n           {\n           crop_buff = seg_buffs[i].buffer;\n           if (writeCroppedImage(in, *out, image, dump,\n                                 crop->regionlist[i].width,\n                                 crop->regionlist[i].length,\n                                 crop_buff, *page, page_count))\n             {\n             TIFFError("writeRegions", "Unable to write new image");\n             return (-1);\n             }\n           }\n         break;\n    case FILE_PER_SELECTION:\n         autoindex = 1;\n\t page_count = 1;\n         for (i = 0; i < crop->selections; i++)\n           {\n           if (update_output_file (out, mp, autoindex, filename, page))\n             return (1);\n           crop_buff = seg_buffs[i].buffer;\n           if (writeCroppedImage(in, *out, image, dump,\n                                 crop->regionlist[i].width,\n                                 crop->regionlist[i].length,\n                                 crop_buff, *page, page_count))\n             {\n             TIFFError("writeRegions", "Unable to write new image");\n             return (-1);\n             }\n           }\n\t break;\n    default: return (1);\n    }\n  return (0);\n  }', 'static int\nupdate_output_file (TIFF **tiffout, char *mode, int autoindex,\n                    char *outname, unsigned int *page)\n  {\n  static int findex = 0;\n  char  *sep;\n  char   filenum[16];\n  char   export_ext[16];\n  char   exportname[PATH_MAX];\n  if (autoindex && (*tiffout != NULL))\n    {\n    TIFFClose (*tiffout);\n    *tiffout = NULL;\n    }\n  strcpy (export_ext, ".tiff");\n  memset (exportname, \'\\0\', PATH_MAX);\n  strncpy (exportname, outname, PATH_MAX - 16);\n  if (*tiffout == NULL)\n    {\n    if (autoindex)\n      {\n      findex++;\n      if ((sep = strstr(exportname, ".tif")) || (sep = strstr(exportname, ".TIF")))\n        {\n        strncpy (export_ext, sep, 5);\n        *sep = \'\\0\';\n        }\n      else\n        strncpy (export_ext, ".tiff", 5);\n      export_ext[5] = \'\\0\';\n      if (findex > MAX_EXPORT_PAGES)\n\t{\n\tTIFFError("update_output_file", "Maximum of %d pages per file exceeded", MAX_EXPORT_PAGES);\n        return 1;\n        }\n      snprintf(filenum, sizeof(filenum), "-%03d%s", findex, export_ext);\n      filenum[14] = \'\\0\';\n      strncat (exportname, filenum, 15);\n      }\n    exportname[PATH_MAX - 1] = \'\\0\';\n    *tiffout = TIFFOpen(exportname, mode);\n    if (*tiffout == NULL)\n      {\n      TIFFError("update_output_file", "Unable to open output file %s", exportname);\n      return 1;\n      }\n    *page = 0;\n    return 0;\n    }\n  else\n    (*page)++;\n  return 0;\n  }', 'static int\nwriteCroppedImage(TIFF *in, TIFF *out, struct image_data *image,\n                  struct dump_opts *dump, uint32 width, uint32 length,\n                  unsigned char *crop_buff, int pagenum, int total_pages)\n  {\n  uint16 bps, spp;\n  uint16 input_compression, input_photometric;\n  uint16 input_planar;\n  struct cpTag* p;\n  input_compression = image->compression;\n  input_photometric = image->photometric;\n  spp = image->spp;\n  bps = image->bps;\n  TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);\n  TIFFSetField(out, TIFFTAG_IMAGELENGTH, length);\n  TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bps);\n  TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, spp);\n#ifdef DEBUG2\n  TIFFError("writeCroppedImage", "Input compression: %s",\n\t    (input_compression == COMPRESSION_OJPEG) ? "Old Jpeg" :\n\t    ((input_compression == COMPRESSION_JPEG) ?  "New Jpeg" : "Non Jpeg"));\n#endif\n  if (compression != (uint16)-1)\n    TIFFSetField(out, TIFFTAG_COMPRESSION, compression);\n  else\n    {\n    if (input_compression == COMPRESSION_OJPEG)\n      {\n      compression = COMPRESSION_JPEG;\n      jpegcolormode = JPEGCOLORMODE_RAW;\n      TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);\n      }\n    else\n      CopyField(TIFFTAG_COMPRESSION, compression);\n    }\n  if (compression == COMPRESSION_JPEG)\n    {\n    if ((input_photometric == PHOTOMETRIC_PALETTE) ||\n        (input_photometric == PHOTOMETRIC_MASK))\n      {\n      TIFFError ("writeCroppedImage",\n                 "JPEG compression cannot be used with %s image data",\n      \t        (input_photometric == PHOTOMETRIC_PALETTE) ?\n                 "palette" : "mask");\n      return (-1);\n      }\n    if ((input_photometric == PHOTOMETRIC_RGB) &&\n\t(jpegcolormode == JPEGCOLORMODE_RGB))\n      TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);\n    else\n\tTIFFSetField(out, TIFFTAG_PHOTOMETRIC, input_photometric);\n    }\n  else\n    {\n    if (compression == COMPRESSION_SGILOG || compression == COMPRESSION_SGILOG24)\n      {\n      TIFFSetField(out, TIFFTAG_PHOTOMETRIC, spp == 1 ?\n\t\t\tPHOTOMETRIC_LOGL : PHOTOMETRIC_LOGLUV);\n      }\n    else\n      {\n      if (input_compression == COMPRESSION_SGILOG ||\n          input_compression == COMPRESSION_SGILOG24)\n        {\n        TIFFSetField(out, TIFFTAG_PHOTOMETRIC, spp == 1 ?\n\t\t\t  PHOTOMETRIC_LOGL : PHOTOMETRIC_LOGLUV);\n        }\n      else\n        TIFFSetField(out, TIFFTAG_PHOTOMETRIC, image->photometric);\n      }\n    }\n  if (((input_photometric == PHOTOMETRIC_LOGL) ||\n       (input_photometric ==  PHOTOMETRIC_LOGLUV)) &&\n      ((compression != COMPRESSION_SGILOG) &&\n       (compression != COMPRESSION_SGILOG24)))\n    {\n    TIFFError("writeCroppedImage",\n              "LogL and LogLuv source data require SGI_LOG or SGI_LOG24 compression");\n    return (-1);\n    }\n  if (fillorder != 0)\n    TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);\n  else\n    CopyTag(TIFFTAG_FILLORDER, 1, TIFF_SHORT);\n  TIFFSetField(out, TIFFTAG_ORIENTATION, image->orientation);\n  if (outtiled == -1)\n    outtiled = TIFFIsTiled(in);\n  if (outtiled) {\n    if (tilewidth == (uint32) 0)\n      TIFFGetField(in, TIFFTAG_TILEWIDTH, &tilewidth);\n    if (tilelength == (uint32) 0)\n      TIFFGetField(in, TIFFTAG_TILELENGTH, &tilelength);\n    if (tilewidth == 0 || tilelength == 0)\n      TIFFDefaultTileSize(out, &tilewidth, &tilelength);\n    TIFFSetField(out, TIFFTAG_TILEWIDTH, tilewidth);\n    TIFFSetField(out, TIFFTAG_TILELENGTH, tilelength);\n    } else {\n\tif (rowsperstrip == (uint32) 0)\n          {\n\t  if (!TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &rowsperstrip))\n\t    rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);\n          if (compression != COMPRESSION_JPEG)\n            {\n  \t    if (rowsperstrip > length)\n\t      rowsperstrip = length;\n\t    }\n\t  }\n\telse\n          if (rowsperstrip == (uint32) -1)\n\t    rowsperstrip = length;\n\tTIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip);\n\t}\n  TIFFGetFieldDefaulted(in, TIFFTAG_PLANARCONFIG, &input_planar);\n  if (config != (uint16) -1)\n    TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);\n  else\n    CopyField(TIFFTAG_PLANARCONFIG, config);\n  if (spp <= 4)\n    CopyTag(TIFFTAG_TRANSFERFUNCTION, 4, TIFF_SHORT);\n  CopyTag(TIFFTAG_COLORMAP, 4, TIFF_SHORT);\n  switch (compression) {\n    case COMPRESSION_JPEG:\n         if (((bps % 8) == 0) || ((bps % 12) == 0))\n\t   {\n           TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);\n\t   TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n           }\n         else\n           {\n\t   TIFFError("writeCroppedImage",\n                     "JPEG compression requires 8 or 12 bits per sample");\n           return (-1);\n           }\n\t break;\n   case COMPRESSION_LZW:\n   case COMPRESSION_ADOBE_DEFLATE:\n   case COMPRESSION_DEFLATE:\n\tif (predictor != (uint16)-1)\n          TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);\n\telse\n\t  CopyField(TIFFTAG_PREDICTOR, predictor);\n\tbreak;\n   case COMPRESSION_CCITTFAX3:\n   case COMPRESSION_CCITTFAX4:\n        if (bps != 1)\n          {\n\t  TIFFError("writeCroppedImage",\n            "Group 3/4 compression is not usable with bps > 1");\n          return (-1);\n\t  }\n\tif (compression == COMPRESSION_CCITTFAX3) {\n          if (g3opts != (uint32) -1)\n\t    TIFFSetField(out, TIFFTAG_GROUP3OPTIONS, g3opts);\n\t  else\n\t    CopyField(TIFFTAG_GROUP3OPTIONS, g3opts);\n\t} else\n\t    CopyTag(TIFFTAG_GROUP4OPTIONS, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_BADFAXLINES, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_CLEANFAXDATA, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_CONSECUTIVEBADFAXLINES, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_FAXRECVPARAMS, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_FAXRECVTIME, 1, TIFF_LONG);\n\t    CopyTag(TIFFTAG_FAXSUBADDRESS, 1, TIFF_ASCII);\n\t break;\n    case COMPRESSION_NONE:\n         break;\n    default: break;\n   }\n   { uint32 len32;\n     void** data;\n     if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &len32, &data))\n       TIFFSetField(out, TIFFTAG_ICCPROFILE, len32, data);\n   }\n   { uint16 ninks;\n     const char* inknames;\n     if (TIFFGetField(in, TIFFTAG_NUMBEROFINKS, &ninks)) {\n       TIFFSetField(out, TIFFTAG_NUMBEROFINKS, ninks);\n       if (TIFFGetField(in, TIFFTAG_INKNAMES, &inknames)) {\n\t int inknameslen = strlen(inknames) + 1;\n\t const char* cp = inknames;\n\t while (ninks > 1) {\n\t   cp = strchr(cp, \'\\0\');\n\t   if (cp) {\n\t     cp++;\n\t     inknameslen += (strlen(cp) + 1);\n\t   }\n\t   ninks--;\n         }\n\t TIFFSetField(out, TIFFTAG_INKNAMES, inknameslen, inknames);\n       }\n     }\n   }\n   {\n   unsigned short pg0, pg1;\n   if (TIFFGetField(in, TIFFTAG_PAGENUMBER, &pg0, &pg1)) {\n     TIFFSetField(out, TIFFTAG_PAGENUMBER, pagenum, total_pages);\n     }\n   }\n  for (p = tags; p < &tags[NTAGS]; p++)\n\t\tCopyTag(p->tag, p->count, p->type);\n  if (outtiled)\n    {\n    if (config == PLANARCONFIG_CONTIG)\n      {\n      if (writeBufferToContigTiles (out, crop_buff, length, width, spp, dump))\n        TIFFError("","Unable to write contiguous tile data for page %d", pagenum);\n      }\n    else\n      {\n      if (writeBufferToSeparateTiles (out, crop_buff, length, width, spp, dump))\n        TIFFError("","Unable to write separate tile data for page %d", pagenum);\n      }\n    }\n  else\n    {\n    if (config == PLANARCONFIG_CONTIG)\n      {\n      if (writeBufferToContigStrips (out, crop_buff, length))\n        TIFFError("","Unable to write contiguous strip data for page %d", pagenum);\n      }\n    else\n      {\n      if (writeBufferToSeparateStrips(out, crop_buff, length, width, spp, dump))\n        TIFFError("","Unable to write separate strip data for page %d", pagenum);\n      }\n    }\n  if (!TIFFWriteDirectory(out))\n    {\n    TIFFError("","Failed to write IFD for page number %d", pagenum);\n    TIFFClose(out);\n    return (-1);\n    }\n  return (0);\n  }', 'static int\nwriteBufferToSeparateStrips (TIFF* out, uint8* buf,\n\t\t\t     uint32 length, uint32 width, uint16 spp,\n\t\t\t     struct dump_opts *dump)\n  {\n  uint8   *src;\n  uint16   bps;\n  uint32   row, nrows, rowsize, rowsperstrip;\n  uint32   bytes_per_sample;\n  tsample_t s;\n  tstrip_t strip = 0;\n  tsize_t  stripsize = TIFFStripSize(out);\n  tsize_t  rowstripsize,  scanlinesize = TIFFScanlineSize(out);\n  tsize_t  total_bytes = 0;\n  tdata_t  obuf;\n  (void) TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);\n  (void) TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps);\n  bytes_per_sample = (bps + 7) / 8;\n  rowsize = ((bps * spp * width) + 7) / 8;\n  rowstripsize = rowsperstrip * bytes_per_sample * (width + 1);\n  obuf = _TIFFmalloc (rowstripsize);\n  if (obuf == NULL)\n    return 1;\n  for (s = 0; s < spp; s++)\n    {\n    for (row = 0; row < length; row += rowsperstrip)\n      {\n      nrows = (row + rowsperstrip > length) ? length - row : rowsperstrip;\n      stripsize = TIFFVStripSize(out, nrows);\n      src = buf + (row * rowsize);\n      total_bytes += stripsize;\n      memset (obuf, \'\\0\', rowstripsize);\n      if (extractContigSamplesToBuffer(obuf, src, nrows, width, s, spp, bps, dump))\n        {\n        _TIFFfree(obuf);\n        return 1;\n\t}\n      if ((dump->outfile != NULL) && (dump->level == 1))\n        {\n        dump_info(dump->outfile, dump->format,"",\n                  "Sample %2d, Strip: %2d, bytes: %4d, Row %4d, bytes: %4d, Input offset: %6d",\n                  s + 1, strip + 1, stripsize, row + 1, scanlinesize, src - buf);\n        dump_buffer(dump->outfile, dump->format, nrows, scanlinesize, row, obuf);\n\t}\n      if (TIFFWriteEncodedStrip(out, strip++, obuf, stripsize) < 0)\n        {\n\tTIFFError(TIFFFileName(out), "Error, can\'t write strip %u", strip - 1);\n\t_TIFFfree(obuf);\n\treturn 1;\n\t}\n      }\n    }\n  _TIFFfree(obuf);\n  return 0;\n}', 'tmsize_t\nTIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)\n{\n\tstatic const char module[] = "TIFFWriteEncodedStrip";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint16 sample;\n\tif (!WRITECHECKSTRIPS(tif, module))\n\t\treturn ((tmsize_t) -1);\n\tif (strip >= td->td_nstrips) {\n\t\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t    "Can not grow image by strips when using separate planes");\n\t\t\treturn ((tmsize_t) -1);\n\t\t}\n\t\tif (!TIFFGrowStrips(tif, 1, module))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttd->td_stripsperimage =\n\t\t    TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);\n\t}\n\tif (!BUFFERCHECK(tif))\n\t\treturn ((tmsize_t) -1);\n        tif->tif_flags |= TIFF_BUF4WRITE;\n\ttif->tif_curstrip = strip;\n\ttif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupencode)(tif))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\tif( td->td_stripbytecount[strip] > 0 )\n        {\n            if( tif->tif_rawdatasize <= (tmsize_t)td->td_stripbytecount[strip] )\n            {\n                if( !(TIFFWriteBufferSetup(tif, NULL,\n                    (tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[strip] + 1), 1024))) )\n                    return ((tmsize_t)(-1));\n            }\n            tif->tif_curoff = 0;\n        }\n    tif->tif_rawcc = 0;\n    tif->tif_rawcp = tif->tif_rawdata;\n\ttif->tif_flags &= ~TIFF_POSTENCODE;\n\tsample = (uint16)(strip / td->td_stripsperimage);\n\tif (!(*tif->tif_preencode)(tif, sample))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_postdecode( tif, (uint8*) data, cc );\n\tif (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample))\n\t\treturn (0);\n\tif (!(*tif->tif_postencode)(tif))\n\t\treturn ((tmsize_t) -1);\n\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t    (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\tTIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);\n\tif (tif->tif_rawcc > 0 &&\n\t    !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n\treturn (cc);\n}']