From 55a0b9e04c627d2089b16fbdc542b3aae18226e6 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 09:49:37 +0000 Subject: Prepare for a new update Reverting patches so we can apply the latest update and changes can be seen in the spec file and sources. --- diff --git a/configure.ac b/configure.ac index 142b5ff..e0e0ae1 100644 --- a/configure.ac +++ b/configure.ac @@ -24,7 +24,7 @@ dnl OF THIS SOFTWARE. dnl Process this file with autoconf to produce a configure script. -AC_PREREQ(2.63) +AC_PREREQ(2.64) AC_INIT([LibTIFF Software],[3.9.4],[tiff@lists.maptools.org],[tiff]) AC_CONFIG_AUX_DIR(config) AC_CONFIG_MACRO_DIR(m4) diff --git a/contrib/addtiffo/tif_ovrcache.c b/contrib/addtiffo/tif_ovrcache.c index 1d183ab..646b534 100644 --- a/contrib/addtiffo/tif_ovrcache.c +++ b/contrib/addtiffo/tif_ovrcache.c @@ -110,7 +110,6 @@ TIFFOvrCache *TIFFCreateOvrCache( TIFF *hTIFF, int nDirOffset ) TIFFErrorExt( hTIFF->tif_clientdata, hTIFF->tif_name, "Can't allocate memory for overview cache." ); /* TODO: use of TIFFError is inconsistent with use of fprintf in addtiffo.c, sort out */ - _TIFFfree( psCache ); return NULL; } diff --git a/contrib/dbs/xtiff/xtiff.c b/contrib/dbs/xtiff/xtiff.c index bbeca95..7fe3977 100644 --- a/contrib/dbs/xtiff/xtiff.c +++ b/contrib/dbs/xtiff/xtiff.c @@ -512,9 +512,9 @@ SetNameLabel() Arg args[1]; if (tfMultiPage) - snprintf(buffer, sizeof(buffer), "%s - page %d", fileName, tfDirectory); + sprintf(buffer, "%s - page %d", fileName, tfDirectory); else - snprintf(buffer, sizeof(buffer), "%s", fileName); + strcpy(buffer, fileName); XtSetArg(args[0], XtNlabel, buffer); XtSetValues(labelWidget, args, 1); } diff --git a/contrib/iptcutil/iptcutil.c b/contrib/iptcutil/iptcutil.c index b6be247..557a67e 100644 --- a/contrib/iptcutil/iptcutil.c +++ b/contrib/iptcutil/iptcutil.c @@ -293,10 +293,8 @@ int formatIPTC(FILE *ifile, FILE *ofile) for (tagindx=0; tagindxtif_dir.td_compression); char compression_code[20]; - snprintf(compression_code, sizeof(compression_code), "%d", - tif->tif_dir.td_compression ); + sprintf( compression_code, "%d", tif->tif_dir.td_compression ); TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%s compression support is not configured", c ? c->name : compression_code ); diff --git a/libtiff/tif_color.c b/libtiff/tif_color.c index eb49132..02eb346 100644 --- a/libtiff/tif_color.c +++ b/libtiff/tif_color.c @@ -183,18 +183,13 @@ void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32 Y, int32 Cb, int32 Cr, uint32 *r, uint32 *g, uint32 *b) { - int32 i; - /* XXX: Only 8-bit YCbCr input supported for now */ Y = HICLAMP(Y, 255), Cb = CLAMP(Cb, 0, 255), Cr = CLAMP(Cr, 0, 255); - i = ycbcr->Y_tab[Y] + ycbcr->Cr_r_tab[Cr]; - *r = CLAMP(i, 0, 255); - i = ycbcr->Y_tab[Y] - + (int)((ycbcr->Cb_g_tab[Cb] + ycbcr->Cr_g_tab[Cr]) >> SHIFT); - *g = CLAMP(i, 0, 255); - i = ycbcr->Y_tab[Y] + ycbcr->Cb_b_tab[Cb]; - *b = CLAMP(i, 0, 255); + *r = ycbcr->clamptab[ycbcr->Y_tab[Y] + ycbcr->Cr_r_tab[Cr]]; + *g = ycbcr->clamptab[ycbcr->Y_tab[Y] + + (int)((ycbcr->Cb_g_tab[Cb] + ycbcr->Cr_g_tab[Cr]) >> SHIFT)]; + *b = ycbcr->clamptab[ycbcr->Y_tab[Y] + ycbcr->Cb_b_tab[Cb]]; } /* diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c index bb5386a..ac44b38 100644 --- a/libtiff/tif_dir.c +++ b/libtiff/tif_dir.c @@ -492,28 +492,31 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap) goto end; } - if (fip->field_tag == TIFFTAG_DOTRANGE - && strcmp(fip->field_name,"DotRange") == 0) { - /* TODO: This is an evil exception and should not have been - handled this way ... likely best if we move it into - the directory structure with an explicit field in - libtiff 4.1 and assign it a FIELD_ value */ - uint16 v[2]; - v[0] = (uint16)va_arg(ap, int); - v[1] = (uint16)va_arg(ap, int); - _TIFFmemcpy(tv->value, v, 4); - } - else if (fip->field_passcount + if ((fip->field_passcount || fip->field_writecount == TIFF_VARIABLE || fip->field_writecount == TIFF_VARIABLE2 || fip->field_writecount == TIFF_SPP - || tv->count > 1) { + || tv->count > 1) + && fip->field_tag != TIFFTAG_PAGENUMBER + && fip->field_tag != TIFFTAG_HALFTONEHINTS + && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING + && fip->field_tag != TIFFTAG_DOTRANGE) { _TIFFmemcpy(tv->value, va_arg(ap, void *), tv->count * tv_size); } else { + /* + * XXX: The following loop required to handle + * TIFFTAG_PAGENUMBER, TIFFTAG_HALFTONEHINTS, + * TIFFTAG_YCBCRSUBSAMPLING and TIFFTAG_DOTRANGE tags. + * These tags are actually arrays and should be passed as + * array pointers to TIFFSetField() function, but actually + * passed as a list of separate values. This behaviour + * must be changed in the future! + */ + int i; char *val = (char *)tv->value; - assert( tv->count == 1 ); + for (i = 0; i < tv->count; i++, val += tv_size) { switch (fip->field_type) { case TIFF_BYTE: case TIFF_UNDEFINED: @@ -572,6 +575,7 @@ _TIFFVSetField(TIFF* tif, ttag_t tag, va_list ap) status = 0; break; } + } } } } @@ -862,27 +866,24 @@ _TIFFVGetField(TIFF* tif, ttag_t tag, va_list ap) *va_arg(ap, uint16*) = (uint16)tv->count; *va_arg(ap, void **) = tv->value; ret_val = 1; - } else if (fip->field_tag == TIFFTAG_DOTRANGE - && strcmp(fip->field_name,"DotRange") == 0) { - /* TODO: This is an evil exception and should not have been - handled this way ... likely best if we move it into - the directory structure with an explicit field in - libtiff 4.1 and assign it a FIELD_ value */ - *va_arg(ap, uint16*) = ((uint16 *)tv->value)[0]; - *va_arg(ap, uint16*) = ((uint16 *)tv->value)[1]; - ret_val = 1; - } else { - if (fip->field_type == TIFF_ASCII + } else { + if ((fip->field_type == TIFF_ASCII || fip->field_readcount == TIFF_VARIABLE || fip->field_readcount == TIFF_VARIABLE2 || fip->field_readcount == TIFF_SPP - || tv->count > 1) { + || tv->count > 1) + && fip->field_tag != TIFFTAG_PAGENUMBER + && fip->field_tag != TIFFTAG_HALFTONEHINTS + && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING + && fip->field_tag != TIFFTAG_DOTRANGE) { *va_arg(ap, void **) = tv->value; ret_val = 1; } else { + int j; char *val = (char *)tv->value; - assert( tv->count == 1 ); + for (j = 0; j < tv->count; + j++, val += _TIFFDataSize(tv->info->field_type)) { switch (fip->field_type) { case TIFF_BYTE: case TIFF_UNDEFINED: @@ -932,6 +933,7 @@ _TIFFVGetField(TIFF* tif, ttag_t tag, va_list ap) ret_val = 0; break; } + } } } break; diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c index 5cc3006..0a77c97 100644 --- a/libtiff/tif_dirinfo.c +++ b/libtiff/tif_dirinfo.c @@ -873,7 +873,7 @@ _TIFFCreateAnonFieldInfo(TIFF *tif, ttag_t tag, TIFFDataType field_type) * note that this name is a special sign to TIFFClose() and * _TIFFSetupFieldInfo() to free the field */ - snprintf(fld->field_name, 32, "Tag %d", (int) tag); + sprintf(fld->field_name, "Tag %d", (int) tag); return fld; } diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index 8dc40b5..907b531 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -65,35 +65,6 @@ static int TIFFFetchDoubleArray(TIFF*, TIFFDirEntry*, double*); static int TIFFFetchAnyArray(TIFF*, TIFFDirEntry*, double*); static int TIFFFetchShortPair(TIFF*, TIFFDirEntry*); static void ChopUpSingleUncompressedStrip(TIFF*); -static int _TIFFGetMaxColorChannels(uint16 photometric); - -/* - * Return the maximum number of color channels specified for a given photometric - * type. 0 is returned if photometric type isn't supported or no default value - * is defined by the specification. - */ -static int _TIFFGetMaxColorChannels( uint16 photometric ) -{ - switch (photometric) { - case PHOTOMETRIC_PALETTE: - case PHOTOMETRIC_MINISWHITE: - case PHOTOMETRIC_MINISBLACK: - return 1; - case PHOTOMETRIC_YCBCR: - case PHOTOMETRIC_RGB: - case PHOTOMETRIC_CIELAB: - return 3; - case PHOTOMETRIC_SEPARATED: - case PHOTOMETRIC_MASK: - return 4; - case PHOTOMETRIC_LOGL: - case PHOTOMETRIC_LOGLUV: - case PHOTOMETRIC_ITULAB: - case PHOTOMETRIC_ICCLAB: - default: - return 0; - } -} /* * Read the next TIFF directory from a file and convert it to the internal @@ -112,10 +83,8 @@ TIFFReadDirectory(TIFF* tif) const TIFFFieldInfo* fip; size_t fix; uint16 dircount; - uint16 previous_tag = 0; int diroutoforderwarning = 0, compressionknown = 0; int haveunknowntags = 0; - int color_channels; tif->tif_diroff = tif->tif_nextdiroff; /* @@ -194,24 +163,23 @@ TIFFReadDirectory(TIFF* tif) if (dp->tdir_tag == IGNORE) continue; + if (fix >= tif->tif_nfields) + fix = 0; /* * Silicon Beach (at least) writes unordered * directory tags (violating the spec). Handle * it here, but be obnoxious (maybe they'll fix it?). */ - if (dp->tdir_tag < previous_tag) { + if (dp->tdir_tag < tif->tif_fieldinfo[fix]->field_tag) { if (!diroutoforderwarning) { TIFFWarningExt(tif->tif_clientdata, module, "%s: invalid TIFF directory; tags are not sorted in ascending order", tif->tif_name); diroutoforderwarning = 1; } - } - previous_tag = dp->tdir_tag; - if (fix >= tif->tif_nfields || - dp->tdir_tag < tif->tif_fieldinfo[fix]->field_tag) fix = 0; /* O(n^2) */ + } while (fix < tif->tif_nfields && tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag) fix++; @@ -647,37 +615,6 @@ TIFFReadDirectory(TIFF* tif) } } } - - /* - * Make sure all non-color channels are extrasamples. - * If it's not the case, define them as such. - */ - color_channels = _TIFFGetMaxColorChannels(tif->tif_dir.td_photometric); - if (color_channels && tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples > color_channels) { - uint16 old_extrasamples; - uint16 *new_sampleinfo; - - TIFFWarningExt(tif->tif_clientdata,module, "Sum of Photometric type-related " - "color channels and ExtraSamples doesn't match SamplesPerPixel. " - "Defining non-color channels as ExtraSamples."); - - old_extrasamples = tif->tif_dir.td_extrasamples; - tif->tif_dir.td_extrasamples = (tif->tif_dir.td_samplesperpixel - color_channels); - - // sampleinfo should contain information relative to these new extra samples - new_sampleinfo = (uint16*) _TIFFcalloc(tif->tif_dir.td_extrasamples, sizeof(uint16)); - if (!new_sampleinfo) { - TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate memory for " - "temporary new sampleinfo array (%d 16 bit elements)", - tif->tif_dir.td_extrasamples); - goto bad; - } - - memcpy(new_sampleinfo, tif->tif_dir.td_sampleinfo, old_extrasamples * sizeof(uint16)); - _TIFFsetShortArray(&tif->tif_dir.td_sampleinfo, new_sampleinfo, tif->tif_dir.td_extrasamples); - _TIFFfree(new_sampleinfo); - } - /* * Verify Palette image has a Colormap. */ diff --git a/libtiff/tif_fax3.h b/libtiff/tif_fax3.h index 8f63d8c..40718bc 100644 --- a/libtiff/tif_fax3.h +++ b/libtiff/tif_fax3.h @@ -478,12 +478,6 @@ done1d: \ break; \ case S_VL: \ CHECK_b1; \ - if (b1 <= (int) (a0 + TabEnt->Param)) { \ - if (b1 < (int) (a0 + TabEnt->Param) || pa != thisrun) { \ - unexpected("VL", a0); \ - goto eol2d; \ - } \ - } \ SETVALUE(b1 - a0 - TabEnt->Param); \ b1 -= *--pb; \ break; \ diff --git a/libtiff/tif_getimage.c b/libtiff/tif_getimage.c index 6db0a4b..38455fb 100644 --- a/libtiff/tif_getimage.c +++ b/libtiff/tif_getimage.c @@ -673,24 +673,18 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) unsigned char* p2; unsigned char* pa; tsize_t tilesize; - tsize_t bufsize; int32 fromskew, toskew; int alpha = img->alpha; uint32 nrow; int ret = 1, flip; tilesize = TIFFTileSize(tif); - bufsize = TIFFSafeMultiply(tsize_t,alpha?4:3,tilesize); - if (bufsize == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtTileSeparate"); - return (0); - } - buf = (unsigned char*) _TIFFmalloc(bufsize); + buf = (unsigned char*) _TIFFmalloc((alpha?4:3)*tilesize); if (buf == 0) { TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer"); return (0); } - _TIFFmemset(buf, 0, bufsize); + _TIFFmemset(buf, 0, (alpha?4:3)*tilesize); p0 = buf; p1 = p0 + tilesize; p2 = p1 + tilesize; @@ -886,23 +880,17 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) uint32 rowsperstrip, offset_row; uint32 imagewidth = img->width; tsize_t stripsize; - tsize_t bufsize; int32 fromskew, toskew; int alpha = img->alpha; int ret = 1, flip; stripsize = TIFFStripSize(tif); - bufsize = TIFFSafeMultiply(tsize_t,alpha?4:3,stripsize); - if (bufsize == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtStripSeparate"); - return (0); - } - p0 = buf = (unsigned char *)_TIFFmalloc(bufsize); + p0 = buf = (unsigned char *)_TIFFmalloc((alpha?4:3)*stripsize); if (buf == 0) { TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer"); return (0); } - _TIFFmemset(buf, 0, bufsize); + _TIFFmemset(buf, 0, (alpha?4:3)*stripsize); p1 = p0 + stripsize; p2 = p1 + stripsize; pa = (alpha?(p2+stripsize):NULL); @@ -1858,7 +1846,6 @@ DECLAREContigPutFunc(putcontig8bitYCbCr41tile) DECLAREContigPutFunc(putcontig8bitYCbCr22tile) { uint32* cp2; - int32 incr = 2*toskew+w; (void) y; fromskew = (fromskew / 2) * 6; cp2 = cp+w+toskew; @@ -1885,8 +1872,8 @@ DECLAREContigPutFunc(putcontig8bitYCbCr22tile) cp2 ++ ; pp += 6; } - cp += incr; - cp2 += incr; + cp += toskew*2+w; + cp2 += toskew*2+w; pp += fromskew; h-=2; } @@ -1952,7 +1939,6 @@ DECLAREContigPutFunc(putcontig8bitYCbCr21tile) DECLAREContigPutFunc(putcontig8bitYCbCr12tile) { uint32* cp2; - int32 incr = 2*toskew+w; (void) y; fromskew = (fromskew / 2) * 4; cp2 = cp+w+toskew; @@ -1967,8 +1953,8 @@ DECLAREContigPutFunc(putcontig8bitYCbCr12tile) cp2 ++; pp += 4; } while (--x); - cp += incr; - cp2 += incr; + cp += toskew*2+w; + cp2 += toskew*2+w; pp += fromskew; h-=2; } @@ -2411,7 +2397,7 @@ PickContigCase(TIFFRGBAImage* img) } break; case PHOTOMETRIC_YCBCR: - if ((img->bitspersample==8) && (img->samplesperpixel==3)) + if (img->bitspersample == 8) { if (initYCbCrConversion(img)!=0) { diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c index ec8485b..a967827 100644 --- a/libtiff/tif_jpeg.c +++ b/libtiff/tif_jpeg.c @@ -988,15 +988,8 @@ JPEGDecodeRaw(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s) tsize_t nrows; (void) s; - nrows = cc / sp->bytesperline; - if (cc % sp->bytesperline) - TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline not read"); - - if( nrows > (int) sp->cinfo.d.image_height ) - nrows = sp->cinfo.d.image_height; - - /* data is expected to be read in multiples of a scanline */ - if (nrows) { + /* data is expected to be read in multiples of a scanline */ + if ( (nrows = sp->cinfo.d.image_height) ) { /* Cb,Cr both have sampling factors 1, so this is correct */ JDIMENSION clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width; int samples_per_clump = sp->samplesperclump; @@ -1094,7 +1087,8 @@ JPEGDecodeRaw(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s) * TODO: resolve this */ buf += sp->bytesperline; cc -= sp->bytesperline; - } while (--nrows > 0); + nrows -= sp->v_sampling; + } while (nrows > 0); #ifdef JPEG_LIB_MK1 _TIFFfree(tmpbuf); diff --git a/libtiff/tif_ojpeg.c b/libtiff/tif_ojpeg.c index 3005dcd..9ae856c 100644 --- a/libtiff/tif_ojpeg.c +++ b/libtiff/tif_ojpeg.c @@ -1392,15 +1392,11 @@ OJPEGReadHeaderInfoSecStreamDqt(TIFF* tif) nb[sizeof(uint32)+2]=0; nb[sizeof(uint32)+3]=67; if (OJPEGReadBlock(sp,65,&nb[sizeof(uint32)+4])==0) - { - _TIFFfree(nb); return(0); - } o=nb[sizeof(uint32)+4]&15; if (3tif_clientdata,module,"Corrupt DQT marker in JPEG data"); - _TIFFfree(nb); return(0); } if (sp->qtable[o]!=0) @@ -1450,17 +1446,13 @@ OJPEGReadHeaderInfoSecStreamDht(TIFF* tif) nb[sizeof(uint32)+2]=(m>>8); nb[sizeof(uint32)+3]=(m&255); if (OJPEGReadBlock(sp,m-2,&nb[sizeof(uint32)+4])==0) - { - _TIFFfree(nb); return(0); - } o=nb[sizeof(uint32)+4]; if ((o&240)==0) { if (3tif_clientdata,module,"Corrupt DHT marker in JPEG data"); - _TIFFfree(nb); return(0); } if (sp->dctable[o]!=0) @@ -1472,14 +1464,12 @@ OJPEGReadHeaderInfoSecStreamDht(TIFF* tif) if ((o&240)!=16) { TIFFErrorExt(tif->tif_clientdata,module,"Corrupt DHT marker in JPEG data"); - _TIFFfree(nb); return(0); } o&=15; if (3tif_clientdata,module,"Corrupt DHT marker in JPEG data"); - _TIFFfree(nb); return(0); } if (sp->actable[o]!=0) @@ -1547,6 +1537,7 @@ OJPEGReadHeaderInfoSecStreamSof(TIFF* tif, uint8 marker_id) OJPEGReadSkip(sp,4); else { + /* TODO: probably best to also add check on allowed upper bound, especially x, may cause buffer overflow otherwise i think */ /* Y: Number of lines */ if (OJPEGReadWord(sp,&p)==0) return(0); @@ -1564,11 +1555,6 @@ OJPEGReadHeaderInfoSecStreamSof(TIFF* tif, uint8 marker_id) TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data indicates unexpected width"); return(0); } - if ((uint32)p>sp->strile_width) - { - TIFFErrorExt(tif->tif_clientdata,module,"JPEG compressed data image width exceeds expected image width"); - return(0); - } sp->sof_x=p; } /* Nf: Number of image components in frame */ @@ -1934,10 +1920,6 @@ OJPEGReadBufferFill(OJPEGState* sp) sp->in_buffer_file_pos=0; else { - if (sp->tif->tif_dir.td_stripbytecount == 0) { - TIFFErrorExt(sp->tif->tif_clientdata,sp->tif->tif_name,"Strip byte counts are missing"); - return(0); - } sp->in_buffer_file_togo=sp->tif->tif_dir.td_stripbytecount[sp->in_buffer_next_strile]; if (sp->in_buffer_file_togo==0) sp->in_buffer_file_pos=0; diff --git a/libtiff/tif_open.c b/libtiff/tif_open.c index 7578275..3b3b2ce 100644 --- a/libtiff/tif_open.c +++ b/libtiff/tif_open.c @@ -175,7 +175,6 @@ TIFFClientOpen( if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc) { TIFFErrorExt(clientdata, module, "One of the client procedures is NULL pointer."); - _TIFFfree(tif); goto bad2; } tif->tif_readproc = readproc; diff --git a/libtiff/tif_pixarlog.c b/libtiff/tif_pixarlog.c index a4c932c..ed8eb40 100644 --- a/libtiff/tif_pixarlog.c +++ b/libtiff/tif_pixarlog.c @@ -117,9 +117,9 @@ horizontalAccumulateF(uint16 *wp, int n, int stride, float *op, if (n >= stride) { mask = CODE_MASK; if (stride == 3) { - t0 = ToLinearF[cr = (wp[0] & mask)]; - t1 = ToLinearF[cg = (wp[1] & mask)]; - t2 = ToLinearF[cb = (wp[2] & mask)]; + t0 = ToLinearF[cr = wp[0]]; + t1 = ToLinearF[cg = wp[1]]; + t2 = ToLinearF[cb = wp[2]]; op[0] = t0; op[1] = t1; op[2] = t2; @@ -136,10 +136,10 @@ horizontalAccumulateF(uint16 *wp, int n, int stride, float *op, op[2] = t2; } } else if (stride == 4) { - t0 = ToLinearF[cr = (wp[0] & mask)]; - t1 = ToLinearF[cg = (wp[1] & mask)]; - t2 = ToLinearF[cb = (wp[2] & mask)]; - t3 = ToLinearF[ca = (wp[3] & mask)]; + t0 = ToLinearF[cr = wp[0]]; + t1 = ToLinearF[cg = wp[1]]; + t2 = ToLinearF[cb = wp[2]]; + t3 = ToLinearF[ca = wp[3]]; op[0] = t0; op[1] = t1; op[2] = t2; @@ -183,9 +183,9 @@ horizontalAccumulate12(uint16 *wp, int n, int stride, int16 *op, if (n >= stride) { mask = CODE_MASK; if (stride == 3) { - t0 = ToLinearF[cr = (wp[0] & mask)] * SCALE12; - t1 = ToLinearF[cg = (wp[1] & mask)] * SCALE12; - t2 = ToLinearF[cb = (wp[2] & mask)] * SCALE12; + t0 = ToLinearF[cr = wp[0]] * SCALE12; + t1 = ToLinearF[cg = wp[1]] * SCALE12; + t2 = ToLinearF[cb = wp[2]] * SCALE12; op[0] = CLAMP12(t0); op[1] = CLAMP12(t1); op[2] = CLAMP12(t2); @@ -202,10 +202,10 @@ horizontalAccumulate12(uint16 *wp, int n, int stride, int16 *op, op[2] = CLAMP12(t2); } } else if (stride == 4) { - t0 = ToLinearF[cr = (wp[0] & mask)] * SCALE12; - t1 = ToLinearF[cg = (wp[1] & mask)] * SCALE12; - t2 = ToLinearF[cb = (wp[2] & mask)] * SCALE12; - t3 = ToLinearF[ca = (wp[3] & mask)] * SCALE12; + t0 = ToLinearF[cr = wp[0]] * SCALE12; + t1 = ToLinearF[cg = wp[1]] * SCALE12; + t2 = ToLinearF[cb = wp[2]] * SCALE12; + t3 = ToLinearF[ca = wp[3]] * SCALE12; op[0] = CLAMP12(t0); op[1] = CLAMP12(t1); op[2] = CLAMP12(t2); @@ -247,9 +247,9 @@ horizontalAccumulate16(uint16 *wp, int n, int stride, uint16 *op, if (n >= stride) { mask = CODE_MASK; if (stride == 3) { - op[0] = ToLinear16[cr = (wp[0] & mask)]; - op[1] = ToLinear16[cg = (wp[1] & mask)]; - op[2] = ToLinear16[cb = (wp[2] & mask)]; + op[0] = ToLinear16[cr = wp[0]]; + op[1] = ToLinear16[cg = wp[1]]; + op[2] = ToLinear16[cb = wp[2]]; n -= 3; while (n > 0) { wp += 3; @@ -260,10 +260,10 @@ horizontalAccumulate16(uint16 *wp, int n, int stride, uint16 *op, op[2] = ToLinear16[(cb += wp[2]) & mask]; } } else if (stride == 4) { - op[0] = ToLinear16[cr = (wp[0] & mask)]; - op[1] = ToLinear16[cg = (wp[1] & mask)]; - op[2] = ToLinear16[cb = (wp[2] & mask)]; - op[3] = ToLinear16[ca = (wp[3] & mask)]; + op[0] = ToLinear16[cr = wp[0]]; + op[1] = ToLinear16[cg = wp[1]]; + op[2] = ToLinear16[cb = wp[2]]; + op[3] = ToLinear16[ca = wp[3]]; n -= 4; while (n > 0) { wp += 4; @@ -342,9 +342,9 @@ horizontalAccumulate8(uint16 *wp, int n, int stride, unsigned char *op, if (n >= stride) { mask = CODE_MASK; if (stride == 3) { - op[0] = ToLinear8[cr = (wp[0] & mask)]; - op[1] = ToLinear8[cg = (wp[1] & mask)]; - op[2] = ToLinear8[cb = (wp[2] & mask)]; + op[0] = ToLinear8[cr = wp[0]]; + op[1] = ToLinear8[cg = wp[1]]; + op[2] = ToLinear8[cb = wp[2]]; n -= 3; while (n > 0) { n -= 3; @@ -355,10 +355,10 @@ horizontalAccumulate8(uint16 *wp, int n, int stride, unsigned char *op, op[2] = ToLinear8[(cb += wp[2]) & mask]; } } else if (stride == 4) { - op[0] = ToLinear8[cr = (wp[0] & mask)]; - op[1] = ToLinear8[cg = (wp[1] & mask)]; - op[2] = ToLinear8[cb = (wp[2] & mask)]; - op[3] = ToLinear8[ca = (wp[3] & mask)]; + op[0] = ToLinear8[cr = wp[0]]; + op[1] = ToLinear8[cg = wp[1]]; + op[2] = ToLinear8[cb = wp[2]]; + op[3] = ToLinear8[ca = wp[3]]; n -= 4; while (n > 0) { n -= 4; @@ -393,9 +393,9 @@ horizontalAccumulate8abgr(uint16 *wp, int n, int stride, unsigned char *op, mask = CODE_MASK; if (stride == 3) { op[0] = 0; - t1 = ToLinear8[cb = (wp[2] & mask)]; - t2 = ToLinear8[cg = (wp[1] & mask)]; - t3 = ToLinear8[cr = (wp[0] & mask)]; + t1 = ToLinear8[cb = wp[2]]; + t2 = ToLinear8[cg = wp[1]]; + t3 = ToLinear8[cr = wp[0]]; op[1] = t1; op[2] = t2; op[3] = t3; @@ -413,10 +413,10 @@ horizontalAccumulate8abgr(uint16 *wp, int n, int stride, unsigned char *op, op[3] = t3; } } else if (stride == 4) { - t0 = ToLinear8[ca = (wp[3] & mask)]; - t1 = ToLinear8[cb = (wp[2] & mask)]; - t2 = ToLinear8[cg = (wp[1] & mask)]; - t3 = ToLinear8[cr = (wp[0] & mask)]; + t0 = ToLinear8[ca = wp[3]]; + t1 = ToLinear8[cb = wp[2]]; + t2 = ToLinear8[cg = wp[1]]; + t3 = ToLinear8[cr = wp[0]]; op[0] = t0; op[1] = t1; op[2] = t2; @@ -630,10 +630,10 @@ PixarLogGuessDataFmt(TIFFDirectory *td) return guess; } -static tsize_t -multiply(tsize_t m1, tsize_t m2) +static uint32 +multiply(size_t m1, size_t m2) { - tsize_t bytes = m1 * m2; + uint32 bytes = m1 * m2; if (m1 && bytes / m1 != m2) bytes = 0; @@ -641,20 +641,6 @@ multiply(tsize_t m1, tsize_t m2) return bytes; } -static tsize_t -add_ms(tsize_t m1, tsize_t m2) -{ - tsize_t bytes = m1 + m2; - - /* if either input is zero, assume overflow already occurred */ - if (m1 == 0 || m2 == 0) - bytes = 0; - else if (bytes <= m1 || bytes <= m2) - bytes = 0; - - return bytes; -} - static int PixarLogSetupDecode(TIFF* tif) { @@ -675,8 +661,6 @@ PixarLogSetupDecode(TIFF* tif) td->td_samplesperpixel : 1); tbuf_size = multiply(multiply(multiply(sp->stride, td->td_imagewidth), td->td_rowsperstrip), sizeof(uint16)); - /* add one more stride in case input ends mid-stride */ - tbuf_size = add_ms(tbuf_size, sizeof(uint16) * sp->stride); if (tbuf_size == 0) return (0); sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size); diff --git a/libtiff/tif_print.c b/libtiff/tif_print.c index 1ec4f26..eb4b1e7 100644 --- a/libtiff/tif_print.c +++ b/libtiff/tif_print.c @@ -112,22 +112,16 @@ _TIFFPrintField(FILE* fd, const TIFFFieldInfo *fip, } static int -_TIFFPrettyPrintField(TIFF* tif, const TIFFFieldInfo *fip, FILE* fd, ttag_t tag, +_TIFFPrettyPrintField(TIFF* tif, FILE* fd, ttag_t tag, uint32 value_count, void *raw_data) { TIFFDirectory *td = &tif->tif_dir; - /* do not try to pretty print auto-defined fields */ - if (strncmp(fip->field_name,"Tag ", 4) == 0) { - return 0; - } - switch (tag) { case TIFFTAG_INKSET: - if (value_count == 2 && fip->field_type == TIFF_SHORT) { - fprintf(fd, " Ink Set: "); - switch (*((uint16*)raw_data)) { + fprintf(fd, " Ink Set: "); + switch (*((uint16*)raw_data)) { case INKSET_CMYK: fprintf(fd, "CMYK\n"); break; @@ -136,26 +130,15 @@ _TIFFPrettyPrintField(TIFF* tif, const TIFFFieldInfo *fip, FILE* fd, ttag_t tag, *((uint16*)raw_data), *((uint16*)raw_data)); break; - } - return 1; } - return 0; - + return 1; case TIFFTAG_DOTRANGE: - if (value_count == 2 && fip->field_type == TIFF_SHORT) { - fprintf(fd, " Dot Range: %u-%u\n", - ((uint16*)raw_data)[0], ((uint16*)raw_data)[1]); - return 1; - } - return 0; - + fprintf(fd, " Dot Range: %u-%u\n", + ((uint16*)raw_data)[0], ((uint16*)raw_data)[1]); + return 1; case TIFFTAG_WHITEPOINT: - if (value_count == 2 && fip->field_type == TIFF_RATIONAL) { - fprintf(fd, " White Point: %g-%g\n", - ((float *)raw_data)[0], ((float *)raw_data)[1]); return 1; - } - return 0; - + fprintf(fd, " White Point: %g-%g\n", + ((float *)raw_data)[0], ((float *)raw_data)[1]); return 1; case TIFFTAG_REFERENCEBLACKWHITE: { uint16 i; @@ -195,13 +178,10 @@ _TIFFPrettyPrintField(TIFF* tif, const TIFFFieldInfo *fip, FILE* fd, ttag_t tag, (unsigned long) value_count); return 1; case TIFFTAG_STONITS: - if (value_count == 1 && fip->field_type == TIFF_DOUBLE) { - fprintf(fd, - " Sample to Nits conversion factor: %.4e\n", - *((double*)raw_data)); - return 1; - } - return 0; + fprintf(fd, + " Sample to Nits conversion factor: %.4e\n", + *((double*)raw_data)); + return 1; } return 0; @@ -503,7 +483,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) for (l = 0; l < n; l++) { fprintf(fd, " %2lu: %5u", l, td->td_transferfunction[0][l]); - for (i = 1; i < td->td_samplesperpixel - td->td_extrasamples && i < 3; i++) + for (i = 1; i < td->td_samplesperpixel; i++) fprintf(fd, " %5u", td->td_transferfunction[i][l]); fputc('\n', fd); @@ -538,19 +518,8 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) continue; if(fip->field_passcount) { - if (fip->field_readcount == TIFF_VARIABLE2 ) { - if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1) - continue; - } else if (fip->field_readcount == TIFF_VARIABLE ) { - uint16 small_value_count; - if(TIFFGetField(tif, tag, &small_value_count, &raw_data) != 1) - continue; - value_count = small_value_count; - } else { - assert (fip->field_readcount == TIFF_VARIABLE - || fip->field_readcount == TIFF_VARIABLE2); + if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1) continue; - } } else { if (fip->field_readcount == TIFF_VARIABLE || fip->field_readcount == TIFF_VARIABLE2) @@ -559,23 +528,21 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) value_count = td->td_samplesperpixel; else value_count = fip->field_readcount; - if (fip->field_tag == TIFFTAG_DOTRANGE - && strcmp(fip->field_name,"DotRange") == 0) { - /* TODO: This is an evil exception and should not have been - handled this way ... likely best if we move it into - the directory structure with an explicit field in - libtiff 4.1 and assign it a FIELD_ value */ - static uint16 dotrange[2]; - raw_data = dotrange; - TIFFGetField(tif, tag, dotrange+0, dotrange+1); - } else if (fip->field_type == TIFF_ASCII + if ((fip->field_type == TIFF_ASCII || fip->field_readcount == TIFF_VARIABLE || fip->field_readcount == TIFF_VARIABLE2 || fip->field_readcount == TIFF_SPP - || value_count > 1) { + || value_count > 1) + && fip->field_tag != TIFFTAG_PAGENUMBER + && fip->field_tag != TIFFTAG_HALFTONEHINTS + && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING + && fip->field_tag != TIFFTAG_DOTRANGE) { if(TIFFGetField(tif, tag, &raw_data) != 1) continue; - } else { + } else if (fip->field_tag != TIFFTAG_PAGENUMBER + && fip->field_tag != TIFFTAG_HALFTONEHINTS + && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING + && fip->field_tag != TIFFTAG_DOTRANGE) { raw_data = _TIFFmalloc( _TIFFDataSize(fip->field_type) * value_count); @@ -584,6 +551,24 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) _TIFFfree(raw_data); continue; } + } else { + /* + * XXX: Should be fixed and removed, see the + * notes related to TIFFTAG_PAGENUMBER, + * TIFFTAG_HALFTONEHINTS, + * TIFFTAG_YCBCRSUBSAMPLING and + * TIFFTAG_DOTRANGE tags in tif_dir.c. */ + char *tmp; + raw_data = _TIFFmalloc( + _TIFFDataSize(fip->field_type) + * value_count); + tmp = raw_data; + mem_alloc = 1; + if(TIFFGetField(tif, tag, tmp, + tmp + _TIFFDataSize(fip->field_type)) != 1) { + _TIFFfree(raw_data); + continue; + } } } @@ -593,7 +578,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) * _TIFFPrettyPrintField() fall down and print it as any other * tag. */ - if (_TIFFPrettyPrintField(tif, fip, fd, tag, value_count, raw_data)) { + if (_TIFFPrettyPrintField(tif, fd, tag, value_count, raw_data)) { if(mem_alloc) _TIFFfree(raw_data); continue; diff --git a/libtiff/tif_strip.c b/libtiff/tif_strip.c index b8b9872..63dec6b 100644 --- a/libtiff/tif_strip.c +++ b/libtiff/tif_strip.c @@ -107,7 +107,6 @@ tsize_t TIFFVStripSize(TIFF* tif, uint32 nrows) { TIFFDirectory *td = &tif->tif_dir; - uint32 stripsize; if (nrows == (uint32) -1) nrows = td->td_imagelength; @@ -123,11 +122,11 @@ TIFFVStripSize(TIFF* tif, uint32 nrows) * YCbCr data for the extended image. */ uint16 ycbcrsubsampling[2]; - uint32 w, scanline, samplingarea; + tsize_t w, scanline, samplingarea; - TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING, - ycbcrsubsampling + 0, - ycbcrsubsampling + 1); + TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING, + ycbcrsubsampling + 0, + ycbcrsubsampling + 1 ); samplingarea = ycbcrsubsampling[0]*ycbcrsubsampling[1]; if (samplingarea == 0) { @@ -142,27 +141,13 @@ TIFFVStripSize(TIFF* tif, uint32 nrows) nrows = TIFFroundup(nrows, ycbcrsubsampling[1]); /* NB: don't need TIFFhowmany here 'cuz everything is rounded */ scanline = multiply(tif, nrows, scanline, "TIFFVStripSize"); - /* a zero anywhere in here means overflow, must return zero */ - if (scanline > 0) { - uint32 extra = - multiply(tif, 2, scanline / samplingarea, - "TIFFVStripSize"); - if (extra > 0) - stripsize = summarize(tif, scanline, extra, - "TIFFVStripSize"); - else - stripsize = 0; - } else - stripsize = 0; + return ((tsize_t) + summarize(tif, scanline, + multiply(tif, 2, scanline / samplingarea, + "TIFFVStripSize"), "TIFFVStripSize")); } else - stripsize = multiply(tif, nrows, TIFFScanlineSize(tif), - "TIFFVStripSize"); - /* Because tsize_t is signed, we might have conversion overflow */ - if (((tsize_t) stripsize) < 0) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Integer overflow in %s", "TIFFVStripSize"); - stripsize = 0; - } - return (tsize_t) stripsize; + return ((tsize_t) multiply(tif, nrows, TIFFScanlineSize(tif), + "TIFFVStripSize")); } @@ -249,23 +234,27 @@ TIFFScanlineSize(TIFF* tif) && !isUpSampled(tif)) { uint16 ycbcrsubsampling[2]; - TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING, - ycbcrsubsampling + 0, - ycbcrsubsampling + 1); + TIFFGetField(tif, TIFFTAG_YCBCRSUBSAMPLING, + ycbcrsubsampling + 0, + ycbcrsubsampling + 1); - if (ycbcrsubsampling[0]*ycbcrsubsampling[1] == 0) { + if (ycbcrsubsampling[0] == 0) { TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Invalid YCbCr subsampling"); return 0; } - /* number of sample clumps per line */ - scanline = TIFFhowmany(td->td_imagewidth, + scanline = TIFFroundup(td->td_imagewidth, ycbcrsubsampling[0]); - /* number of samples per line */ - scanline = multiply(tif, scanline, - ycbcrsubsampling[0]*ycbcrsubsampling[1] + 2, - "TIFFScanlineSize"); + scanline = TIFFhowmany8(multiply(tif, scanline, + td->td_bitspersample, + "TIFFScanlineSize")); + return ((tsize_t) + summarize(tif, scanline, + multiply(tif, 2, + scanline / ycbcrsubsampling[0], + "TIFFVStripSize"), + "TIFFVStripSize")); } else { scanline = multiply(tif, td->td_imagewidth, td->td_samplesperpixel, @@ -319,9 +308,9 @@ TIFFNewScanlineSize(TIFF* tif) && !isUpSampled(tif)) { uint16 ycbcrsubsampling[2]; - TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING, - ycbcrsubsampling + 0, - ycbcrsubsampling + 1); + TIFFGetField(tif, TIFFTAG_YCBCRSUBSAMPLING, + ycbcrsubsampling + 0, + ycbcrsubsampling + 1); if (ycbcrsubsampling[0]*ycbcrsubsampling[1] == 0) { TIFFErrorExt(tif->tif_clientdata, tif->tif_name, diff --git a/libtiff/tif_thunder.c b/libtiff/tif_thunder.c index 5fbaa0b..8e7a125 100644 --- a/libtiff/tif_thunder.c +++ b/libtiff/tif_thunder.c @@ -55,32 +55,12 @@ static const int twobitdeltas[4] = { 0, 1, 0, -1 }; static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 }; -#define SETPIXEL(op, v) { \ - lastpixel = (v) & 0xf; \ - if ( npixels < maxpixels ) \ - { \ - if (npixels++ & 1) \ - *op++ |= lastpixel; \ - else \ +#define SETPIXEL(op, v) { \ + lastpixel = (v) & 0xf; \ + if (npixels++ & 1) \ + *op++ |= lastpixel; \ + else \ op[0] = (tidataval_t) (lastpixel << 4); \ - } \ -} - -static int -ThunderSetupDecode(TIFF* tif) -{ - static const char module[] = "ThunderSetupDecode"; - - if( tif->tif_dir.td_bitspersample != 4 ) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Wrong bitspersample value (%d), Thunder decoder only supports 4bits per sample.", - (int) tif->tif_dir.td_bitspersample ); - return 0; - } - - - return (1); } static int @@ -171,7 +151,6 @@ TIFFInitThunderScan(TIFF* tif, int scheme) (void) scheme; tif->tif_decoderow = ThunderDecodeRow; tif->tif_decodestrip = ThunderDecodeRow; - tif->tif_setupdecode = ThunderSetupDecode; return (1); } #endif /* THUNDER_SUPPORT */ diff --git a/libtiff/tif_tile.c b/libtiff/tif_tile.c index 6676a32..d8379e6 100644 --- a/libtiff/tif_tile.c +++ b/libtiff/tif_tile.c @@ -174,7 +174,7 @@ tsize_t TIFFTileRowSize(TIFF* tif) { TIFFDirectory *td = &tif->tif_dir; - uint32 rowsize; + tsize_t rowsize; if (td->td_tilelength == 0 || td->td_tilewidth == 0) return ((tsize_t) 0); @@ -193,7 +193,7 @@ tsize_t TIFFVTileSize(TIFF* tif, uint32 nrows) { TIFFDirectory *td = &tif->tif_dir; - uint32 tilesize; + tsize_t tilesize; if (td->td_tilelength == 0 || td->td_tilewidth == 0 || td->td_tiledepth == 0) @@ -209,12 +209,12 @@ TIFFVTileSize(TIFF* tif, uint32 nrows) * horizontal/vertical subsampling area include * YCbCr data for the extended image. */ - uint32 w = + tsize_t w = TIFFroundup(td->td_tilewidth, td->td_ycbcrsubsampling[0]); - uint32 rowsize = + tsize_t rowsize = TIFFhowmany8(multiply(tif, w, td->td_bitspersample, "TIFFVTileSize")); - uint32 samplingarea = + tsize_t samplingarea = td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1]; if (samplingarea == 0) { TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Invalid YCbCr subsampling"); @@ -223,27 +223,15 @@ TIFFVTileSize(TIFF* tif, uint32 nrows) nrows = TIFFroundup(nrows, td->td_ycbcrsubsampling[1]); /* NB: don't need TIFFhowmany here 'cuz everything is rounded */ tilesize = multiply(tif, nrows, rowsize, "TIFFVTileSize"); - /* a zero anywhere in here means overflow, must return zero */ - if (tilesize > 0) { - uint32 extra = - multiply(tif, 2, tilesize / samplingarea, + tilesize = summarize(tif, tilesize, + multiply(tif, 2, tilesize / samplingarea, + "TIFFVTileSize"), "TIFFVTileSize"); - if (extra > 0) - tilesize = summarize(tif, tilesize, extra, - "TIFFVTileSize"); - else - tilesize = 0; - } } else tilesize = multiply(tif, nrows, TIFFTileRowSize(tif), "TIFFVTileSize"); - tilesize = multiply(tif, tilesize, td->td_tiledepth, "TIFFVTileSize"); - /* Because tsize_t is signed, we might have conversion overflow */ - if (((tsize_t) tilesize) < 0) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Integer overflow in %s", "TIFFVTileSize"); - tilesize = 0; - } - return (tsize_t) tilesize; + return ((tsize_t) + multiply(tif, tilesize, td->td_tiledepth, "TIFFVTileSize")); } /* diff --git a/libtiff/tif_unix.c b/libtiff/tif_unix.c index 5d29040..b73e80d 100644 --- a/libtiff/tif_unix.c +++ b/libtiff/tif_unix.c @@ -241,15 +241,6 @@ _TIFFmalloc(tsize_t s) return (malloc((size_t) s)); } -void* -_TIFFcalloc(tsize_t nmemb, tsize_t siz) -{ - if( nmemb == 0 || siz == 0 ) - return ((void *) NULL); - - return calloc((size_t) nmemb, (size_t)siz); -} - void _TIFFfree(tdata_t p) { diff --git a/libtiff/tiffio.h b/libtiff/tiffio.h index 3cf8e75..06ec25c 100644 --- a/libtiff/tiffio.h +++ b/libtiff/tiffio.h @@ -281,7 +281,6 @@ extern TIFFCodec* TIFFGetConfiguredCODECs(void); */ extern tdata_t _TIFFmalloc(tsize_t); -extern tdata_t _TIFFcalloc(tsize_t, tsize_t); extern tdata_t _TIFFrealloc(tdata_t, tsize_t); extern void _TIFFmemset(tdata_t, int, tsize_t); extern void _TIFFmemcpy(tdata_t, const tdata_t, tsize_t); diff --git a/libtiff/tiffiop.h b/libtiff/tiffiop.h index b8fa5c4..a064039 100644 --- a/libtiff/tiffiop.h +++ b/libtiff/tiffiop.h @@ -243,7 +243,7 @@ struct tiff { #define TIFFroundup(x, y) (TIFFhowmany(x,y)*(y)) /* Safe multiply which returns zero if there is an integer overflow */ -#define TIFFSafeMultiply(t,v,m) ((((t)(m) != (t)0) && (((t)(((v)*(m))/(m))) == (t)(v))) ? (t)((v)*(m)) : (t)0) +#define TIFFSafeMultiply(t,v,m) ((((t)m != (t)0) && (((t)((v*m)/m)) == (t)v)) ? (t)(v*m) : (t)0) #define TIFFmax(A,B) ((A)>(B)?(A):(B)) #define TIFFmin(A,B) ((A)<(B)?(A):(B)) diff --git a/man/tiffset.1 b/man/tiffset.1 index 8c7e214..6906238 100644 --- a/man/tiffset.1 +++ b/man/tiffset.1 @@ -60,7 +60,7 @@ The following example sets the artist tag (315) of a.tif to the string ``Anonymous'': .RS .nf -tiffset \-s 315 Anonymous a.tif +tiffset \-s 305 Anonymous a.tif .fi .RE .PP diff --git a/test/ascii_tag.c b/test/ascii_tag.c index 0e85c8f..bf81212 100644 --- a/test/ascii_tag.c +++ b/test/ascii_tag.c @@ -125,7 +125,7 @@ main(int argc, char **argv) } /* Write dummy pixel data. */ - if (TIFFWriteScanline(tif, buf, 0, 0) == -1) { + if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) { fprintf (stderr, "Can't write image data.\n"); goto failure; } diff --git a/test/long_tag.c b/test/long_tag.c index e895ee4..256bc8e 100644 --- a/test/long_tag.c +++ b/test/long_tag.c @@ -109,7 +109,7 @@ main(int argc, char **argv) } /* Write dummy pixel data. */ - if (TIFFWriteScanline(tif, buf, 0, 0) == -1) { + if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) { fprintf (stderr, "Can't write image data.\n"); goto failure; } diff --git a/test/short_tag.c b/test/short_tag.c index c9e0c21..45214e1 100644 --- a/test/short_tag.c +++ b/test/short_tag.c @@ -123,7 +123,7 @@ main(int argc, char **argv) } /* Write dummy pixel data. */ - if (TIFFWriteScanline(tif, buf, 0, 0) == -1) { + if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) { fprintf (stderr, "Can't write image data.\n"); goto failure; } diff --git a/test/strip.c b/test/strip.c index ab7f5ef..df6406e 100644 --- a/test/strip.c +++ b/test/strip.c @@ -278,7 +278,7 @@ write_scanlines(TIFF *tif, const tdata_t array, const tsize_t size) } for (offset = 0, row = 0; row < length; offset+=scanlinesize, row++) { - if (TIFFWriteScanline(tif, (char *)array + offset, row, 0) == -1) { + if (TIFFWriteScanline(tif, (char *)array + offset, row, 0) < 0) { fprintf (stderr, "Can't write image data at row %u.\n", row); return -1; diff --git a/tools/gif2tiff.c b/tools/gif2tiff.c index 8cf9735..9c2cfa4 100644 --- a/tools/gif2tiff.c +++ b/tools/gif2tiff.c @@ -276,10 +276,6 @@ readgifimage(char* mode) fprintf(stderr, "no colormap present for image\n"); return (0); } - if (width == 0 || height == 0) { - fprintf(stderr, "Invalid value of width or height\n"); - return(0); - } if ((raster = (unsigned char*) _TIFFmalloc(width*height+EXTRAFUDGE)) == NULL) { fprintf(stderr, "not enough memory for image\n"); return (0); @@ -333,10 +329,6 @@ readraster(void) int status = 1; datasize = getc(infile); - - if (datasize > 12) - return 0; - clear = 1 << datasize; eoi = clear + 1; avail = clear + 2; @@ -402,14 +394,6 @@ process(register int code, unsigned char** fill) } if (oldcode == -1) { - if (code >= clear) { - fprintf(stderr, "bad input: code=%d is larger than clear=%d\n",code, clear); - return 0; - } - if (*fill >= raster + width*height) { - fprintf(stderr, "raster full before eoi code\n"); - return 0; - } *(*fill)++ = suffix[code]; firstchar = oldcode = code; return 1; @@ -440,10 +424,6 @@ process(register int code, unsigned char** fill) } oldcode = incode; do { - if (*fill >= raster + width*height) { - fprintf(stderr, "raster full before eoi code\n"); - return 0; - } *(*fill)++ = *--stackp; } while (stackp > stack); return 1; diff --git a/tools/ppm2tiff.c b/tools/ppm2tiff.c index 885714e..6078459 100644 --- a/tools/ppm2tiff.c +++ b/tools/ppm2tiff.c @@ -68,17 +68,6 @@ BadPPM(char* file) exit(-2); } -static tsize_t -multiply_ms(tsize_t m1, tsize_t m2) -{ - tsize_t bytes = m1 * m2; - - if (m1 && bytes / m1 != m2) - bytes = 0; - - return bytes; -} - int main(int argc, char* argv[]) { @@ -96,7 +85,6 @@ main(int argc, char* argv[]) int c; extern int optind; extern char* optarg; - tsize_t scanline_size; if (argc < 2) { fprintf(stderr, "%s: Too few arguments\n", argv[0]); @@ -229,8 +217,7 @@ main(int argc, char* argv[]) } switch (bpp) { case 1: - /* if round-up overflows, result will be zero, OK */ - linebytes = (multiply_ms(spp, w) + (8 - 1)) / 8; + linebytes = (spp * w + (8 - 1)) / 8; if (rowsperstrip == (uint32) -1) { TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, h); } else { @@ -239,31 +226,15 @@ main(int argc, char* argv[]) } break; case 8: - linebytes = multiply_ms(spp, w); + linebytes = spp * w; TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, rowsperstrip)); break; } - if (linebytes == 0) { - fprintf(stderr, "%s: scanline size overflow\n", infile); - (void) TIFFClose(out); - exit(-2); - } - scanline_size = TIFFScanlineSize(out); - if (scanline_size == 0) { - /* overflow - TIFFScanlineSize already printed a message */ - (void) TIFFClose(out); - exit(-2); - } - if (scanline_size < linebytes) + if (TIFFScanlineSize(out) > linebytes) buf = (unsigned char *)_TIFFmalloc(linebytes); else - buf = (unsigned char *)_TIFFmalloc(scanline_size); - if (buf == NULL) { - fprintf(stderr, "%s: Not enough memory\n", infile); - (void) TIFFClose(out); - exit(-2); - } + buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out)); if (resolution > 0) { TIFFSetField(out, TIFFTAG_XRESOLUTION, resolution); TIFFSetField(out, TIFFTAG_YRESOLUTION, resolution); diff --git a/tools/rgb2ycbcr.c b/tools/rgb2ycbcr.c index db1a86f..0b30b51 100644 --- a/tools/rgb2ycbcr.c +++ b/tools/rgb2ycbcr.c @@ -326,8 +326,7 @@ tiffcvt(TIFF* in, TIFF* out) TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); { char buf[2048]; char *cp = strrchr(TIFFFileName(in), '/'); - snprintf(buf, sizeof(buf), "YCbCr conversion of %s", - cp ? cp+1 : TIFFFileName(in)); + sprintf(buf, "YCbCr conversion of %s", cp ? cp+1 : TIFFFileName(in)); TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, buf); } TIFFSetField(out, TIFFTAG_SOFTWARE, TIFFGetVersion()); diff --git a/tools/tiff2bw.c b/tools/tiff2bw.c index dcaef04..9e1e23a 100644 --- a/tools/tiff2bw.c +++ b/tools/tiff2bw.c @@ -201,7 +201,7 @@ main(int argc, char* argv[]) } } TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK); - snprintf(thing, sizeof(thing), "B&W version of %s", argv[optind]); + sprintf(thing, "B&W version of %s", argv[optind]); TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, thing); TIFFSetField(out, TIFFTAG_SOFTWARE, "tiff2bw"); outbuf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out)); diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c index a4ce325..b1886c6 100644 --- a/tools/tiff2pdf.c +++ b/tools/tiff2pdf.c @@ -44,7 +44,6 @@ # include #endif -#include "tiffiop.h" #include "tiffio.h" #ifndef HAVE_GETOPT @@ -415,34 +414,6 @@ t2p_unmapproc(thandle_t handle, tdata_t data, toff_t offset) (void) handle, (void) data, (void) offset; } -static uint64 -checkAdd64(uint64 summand1, uint64 summand2, T2P* t2p) -{ - uint64 bytes = summand1 + summand2; - - if (bytes - summand1 != summand2) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - bytes = 0; - } - - return bytes; -} - -static uint64 -checkMultiply64(uint64 first, uint64 second, T2P* t2p) -{ - uint64 bytes = first * second; - - if (second && bytes / second != first) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - bytes = 0; - } - - return bytes; -} - /* This is the main function. @@ -1119,7 +1090,6 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ "Can't set directory %u of input file %s", i, TIFFFileName(input)); - t2p->t2p_error = T2P_ERR_ERROR; return; } if(TIFFGetField(input, TIFFTAG_PAGENUMBER, &pagen, &paged)){ @@ -1858,7 +1828,9 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ tstrip_t i=0; tstrip_t stripcount=0; #endif - uint64 k = 0; +#ifdef OJPEG_SUPPORT + tsize_t k = 0; +#endif if(t2p->pdf_transcode == T2P_TRANSCODE_RAW){ #ifdef CCITT_SUPPORT @@ -1886,25 +1858,19 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ } stripcount=TIFFNumberOfStrips(input); for(i=0;itiff_dataoffset))){ if(t2p->tiff_dataoffset != 0){ if(TIFFGetField(input, TIFFTAG_JPEGIFBYTECOUNT, &(t2p->tiff_datasize))!=0){ if(t2p->tiff_datasize < k) { + t2p->pdf_ojpegiflength=t2p->tiff_datasize; + t2p->tiff_datasize+=k; + t2p->tiff_datasize+=6; + t2p->tiff_datasize+=2*stripcount; TIFFWarning(TIFF2PDF_MODULE, "Input file %s has short JPEG interchange file byte count", TIFFFileName(input)); - t2p->pdf_ojpegiflength=t2p->tiff_datasize; - k = checkAdd64(k, t2p->tiff_datasize, t2p); - k = checkAdd64(k, 6, t2p); - k = checkAdd64(k, stripcount, t2p); - k = checkAdd64(k, stripcount, t2p); - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } return; } return; @@ -1917,14 +1883,9 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ } } } - k = checkAdd64(k, stripcount, t2p); - k = checkAdd64(k, stripcount, t2p); - k = checkAdd64(k, 2048, t2p); - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } + t2p->tiff_datasize+=k; + t2p->tiff_datasize+=2*stripcount; + t2p->tiff_datasize+=2048; return; } #endif @@ -1933,11 +1894,11 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ uint32 count = 0; if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0 ){ if(count > 4){ - k += count; - k -= 2; /* don't use EOI of header */ + t2p->tiff_datasize += count; + t2p->tiff_datasize -= 2; /* don't use EOI of header */ } } else { - k = 2; /* SOI for first strip */ + t2p->tiff_datasize = 2; /* SOI for first strip */ } stripcount=TIFFNumberOfStrips(input); if(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){ @@ -1948,33 +1909,18 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){ return; } for(i=0;itiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; + t2p->tiff_datasize += sbc[i]; + t2p->tiff_datasize -=4; /* don't use SOI or EOI of strip */ } + t2p->tiff_datasize +=2; /* use EOI of last strip */ return; } #endif (void) 0; } - k = checkMultiply64(TIFFScanlineSize(input), t2p->tiff_length, t2p); + t2p->tiff_datasize=TIFFScanlineSize(input) * t2p->tiff_length; if(t2p->tiff_planar==PLANARCONFIG_SEPARATE){ - k = checkMultiply64(k, t2p->tiff_samplesperpixel, t2p); - } - if (k == 0) { - /* Assume we had overflow inside TIFFScanlineSize */ - t2p->t2p_error = T2P_ERR_ERROR; - } - - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; + t2p->tiff_datasize*= t2p->tiff_samplesperpixel; } return; @@ -1992,7 +1938,6 @@ void t2p_read_tiff_size_tile(T2P* t2p, TIFF* input, ttile_t tile){ #ifdef JPEG_SUPPORT unsigned char* jpt; #endif - uint64 k; edge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile); edge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile); @@ -2004,17 +1949,14 @@ void t2p_read_tiff_size_tile(T2P* t2p, TIFF* input, ttile_t tile){ #endif ){ t2p->tiff_datasize=TIFFTileSize(input); - if (t2p->tiff_datasize == 0) { - /* Assume we had overflow inside TIFFTileSize */ - t2p->t2p_error = T2P_ERR_ERROR; - } return; } else { TIFFGetField(input, TIFFTAG_TILEBYTECOUNTS, &tbc); - k=tbc[tile]; + t2p->tiff_datasize=tbc[tile]; #ifdef OJPEG_SUPPORT if(t2p->tiff_compression==COMPRESSION_OJPEG){ - k = checkAdd64(k, 2048, t2p); + t2p->tiff_datasize+=2048; + return; } #endif #ifdef JPEG_SUPPORT @@ -2022,33 +1964,18 @@ void t2p_read_tiff_size_tile(T2P* t2p, TIFF* input, ttile_t tile){ uint32 count = 0; if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt)!=0){ if(count > 4){ - k = checkAdd64(k, count, t2p); - k -= 4; /* don't use EOI of header or SOI of tile */ + t2p->tiff_datasize += count; + t2p->tiff_datasize -= 4; /* don't use EOI of header or SOI of tile */ } } } #endif - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; - } return; } } - k = TIFFTileSize(input); + t2p->tiff_datasize=TIFFTileSize(input); if(t2p->tiff_planar==PLANARCONFIG_SEPARATE){ - k = checkMultiply64(k, t2p->tiff_samplesperpixel, t2p); - } - if (k == 0) { - /* Assume we had overflow inside TIFFTileSize */ - t2p->t2p_error = T2P_ERR_ERROR; - } - - t2p->tiff_datasize = (tsize_t) k; - if ((uint64) t2p->tiff_datasize != k) { - TIFFError(TIFF2PDF_MODULE, "Integer overflow"); - t2p->t2p_error = T2P_ERR_ERROR; + t2p->tiff_datasize*= t2p->tiff_samplesperpixel; } return; @@ -2141,10 +2068,6 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ uint32 max_striplength=0; #endif - /* Fail if prior error (in particular, can't trust tiff_datasize) */ - if (t2p->t2p_error != T2P_ERR_OK) - return(0); - if(t2p->pdf_transcode == T2P_TRANSCODE_RAW){ #ifdef CCITT_SUPPORT if(t2p->pdf_compression == T2P_COMPRESS_G4){ @@ -2440,7 +2363,6 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){ t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; - _TIFFfree(buffer); return(0); } for(i=0;it2p_error = T2P_ERR_ERROR; _TIFFfree(buffer); - return(0); } else { buffer=samplebuffer; t2p->tiff_datasize *= t2p->tiff_samplesperpixel; @@ -2720,10 +2641,6 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ uint32 xuint32=0; #endif - /* Fail if prior error (in particular, can't trust tiff_datasize) */ - if (t2p->t2p_error != T2P_ERR_OK) - return(0); - edge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile); edge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile); @@ -2920,7 +2837,6 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; - _TIFFfree(buffer); return(0); } samplebufferoffset=0; @@ -3237,7 +3153,6 @@ int t2p_process_ojpeg_tables(T2P* t2p, TIFF* input){ "Can't allocate %u bytes of memory for t2p_process_ojpeg_tables, %s", 2048, TIFFFileName(input)); - t2p->t2p_error = T2P_ERR_ERROR; return(0); } _TIFFmemset(t2p->pdf_ojpegdata, 0x00, 2048); @@ -3396,56 +3311,33 @@ int t2p_process_jpeg_strip( uint32 height){ tsize_t i=0; - - while (i < *striplength) { - tsize_t datalen; - uint16 ri; - uint16 v_samp; - uint16 h_samp; - int j; - int ncomp; - - /* marker header: one or more FFs */ - if (strip[i] != 0xff) - return(0); - i++; - while (i < *striplength && strip[i] == 0xff) - i++; - if (i >= *striplength) - return(0); - /* SOI is the only pre-SOS marker without a length word */ - if (strip[i] == 0xd8) - datalen = 0; - else { - if ((*striplength - i) <= 2) - return(0); - datalen = (strip[i+1] << 8) | strip[i+2]; - if (datalen < 2 || datalen >= (*striplength - i)) - return(0); - } + uint16 ri =0; + uint16 v_samp=1; + uint16 h_samp=1; + int j=0; + + i++; + + while(i<(*striplength)){ switch( strip[i] ){ - case 0xd8: /* SOI - start of image */ + case 0xd8: + /* SOI - start of image */ _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), 2); *bufferoffset+=2; + i+=2; break; - case 0xc0: /* SOF0 */ - case 0xc1: /* SOF1 */ - case 0xc3: /* SOF3 */ - case 0xc9: /* SOF9 */ - case 0xca: /* SOF10 */ + case 0xc0: + case 0xc1: + case 0xc3: + case 0xc9: + case 0xca: if(no==0){ - _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), datalen+2); - ncomp = buffer[*bufferoffset+9]; - if (ncomp < 1 || ncomp > 4) - return(0); - v_samp=1; - h_samp=1; - for(j=0;j>4) > h_samp) - h_samp = (samp>>4); - if( (samp & 0x0f) > v_samp) - v_samp = (samp & 0x0f); + _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), strip[i+2]+2); + for(j=0;j>4) > h_samp) + h_samp = (buffer[*bufferoffset+11+(2*j)]>>4); + if( (buffer[*bufferoffset+11+(2*j)] & 0x0f) > v_samp) + v_samp = (buffer[*bufferoffset+11+(2*j)] & 0x0f); } v_samp*=8; h_samp*=8; @@ -3459,43 +3351,45 @@ int t2p_process_jpeg_strip( (unsigned char) ((height>>8) & 0xff); buffer[*bufferoffset+6]= (unsigned char) (height & 0xff); - *bufferoffset+=datalen+2; - /* insert a DRI marker */ + *bufferoffset+=strip[i+2]+2; + i+=strip[i+2]+2; + buffer[(*bufferoffset)++]=0xff; buffer[(*bufferoffset)++]=0xdd; buffer[(*bufferoffset)++]=0x00; buffer[(*bufferoffset)++]=0x04; buffer[(*bufferoffset)++]=(ri >> 8) & 0xff; buffer[(*bufferoffset)++]= ri & 0xff; + } else { + i+=strip[i+2]+2; } break; - case 0xc4: /* DHT */ - case 0xdb: /* DQT */ - _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), datalen+2); - *bufferoffset+=datalen+2; + case 0xc4: + case 0xdb: + _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), strip[i+2]+2); + *bufferoffset+=strip[i+2]+2; + i+=strip[i+2]+2; break; - case 0xda: /* SOS */ + case 0xda: if(no==0){ - _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), datalen+2); - *bufferoffset+=datalen+2; + _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), strip[i+2]+2); + *bufferoffset+=strip[i+2]+2; + i+=strip[i+2]+2; } else { buffer[(*bufferoffset)++]=0xff; buffer[(*bufferoffset)++]= (unsigned char)(0xd0 | ((no-1)%8)); + i+=strip[i+2]+2; } - i += datalen + 1; - /* copy remainder of strip */ - _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i]), *striplength - i); - *bufferoffset+= *striplength - i; + _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), (*striplength)-i-1); + *bufferoffset+=(*striplength)-i-1; return(1); default: - /* ignore any other marker */ - break; + i+=strip[i+2]+2; } - i += datalen + 1; } + - /* failed to find SOS marker */ return(0); } #endif @@ -3686,9 +3580,7 @@ tsize_t t2p_write_pdf_header(T2P* t2p, TIFF* output){ char buffer[16]; int buflen=0; - buflen = snprintf(buffer, sizeof(buffer), "%%PDF-%u.%u ", - t2p->pdf_majorversion&0xff, - t2p->pdf_minorversion&0xff); + buflen=sprintf(buffer, "%%PDF-%u.%u ", t2p->pdf_majorversion&0xff, t2p->pdf_minorversion&0xff); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t)"\n%\342\343\317\323\n", 7); @@ -3702,10 +3594,10 @@ tsize_t t2p_write_pdf_header(T2P* t2p, TIFF* output){ tsize_t t2p_write_pdf_obj_start(uint32 number, TIFF* output){ tsize_t written=0; - char buffer[32]; + char buffer[16]; int buflen=0; - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)number); + buflen=sprintf(buffer, "%lu", (unsigned long)number); written += t2pWriteFile(output, (tdata_t) buffer, buflen ); written += t2pWriteFile(output, (tdata_t) " 0 obj\n", 7); @@ -3744,13 +3636,13 @@ tsize_t t2p_write_pdf_name(unsigned char* name, TIFF* output){ written += t2pWriteFile(output, (tdata_t) "/", 1); for (i=0;i 0x7E){ - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); nextchar=1; @@ -3758,57 +3650,57 @@ tsize_t t2p_write_pdf_name(unsigned char* name, TIFF* output){ if (nextchar==0){ switch (name[i]){ case 0x23: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; case 0x25: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; case 0x28: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; case 0x29: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; case 0x2F: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; case 0x3C: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; case 0x3E: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; case 0x5B: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; case 0x5D: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; case 0x7B: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; case 0x7D: - snprintf(buffer, sizeof(buffer), "#%.2X", name[i]); + sprintf(buffer, "#%.2X", name[i]); buffer[sizeof(buffer) - 1] = '\0'; written += t2pWriteFile(output, (tdata_t) buffer, 3); break; @@ -3838,7 +3730,7 @@ tsize_t t2p_write_pdf_string(unsigned char* pdfstr, TIFF* output){ written += t2pWriteFile(output, (tdata_t) "(", 1); for (i=0; ipdf_pages); + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_pages); written += t2pWriteFile(output, (tdata_t) buffer, buflen ); written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6); if(t2p->pdf_fitwindow){ @@ -4029,7 +3921,8 @@ tsize_t t2p_write_pdf_info(T2P* t2p, TIFF* input, TIFF* output){ written += t2p_write_pdf_string(t2p->pdf_datetime, output); } written += t2pWriteFile(output, (tdata_t) "\n/Producer ", 11); - buflen = snprintf(buffer, sizeof(buffer), "libtiff / tiff2pdf - %d", TIFFLIB_VERSION); + _TIFFmemset((tdata_t)buffer, 0x00, sizeof(buffer)); + buflen = sprintf(buffer, "libtiff / tiff2pdf - %d", TIFFLIB_VERSION); written += t2p_write_pdf_string((unsigned char*)buffer, output); written += t2pWriteFile(output, (tdata_t) "\n", 1); if(t2p->pdf_creator != NULL){ @@ -4204,7 +4097,7 @@ tsize_t t2p_write_pdf_pages(T2P* t2p, TIFF* output) { tsize_t written=0; tdir_t i=0; - char buffer[32]; + char buffer[16]; int buflen=0; int page=0; @@ -4212,7 +4105,7 @@ tsize_t t2p_write_pdf_pages(T2P* t2p, TIFF* output) (tdata_t) "<< \n/Type /Pages \n/Kids [ ", 26); page = t2p->pdf_pages+1; for (i=0;itiff_pagecount;i++){ - buflen=snprintf(buffer, sizeof(buffer), "%d", page); + buflen=sprintf(buffer, "%d", page); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); if ( ((i+1)%8)==0 ) { @@ -4227,7 +4120,8 @@ tsize_t t2p_write_pdf_pages(T2P* t2p, TIFF* output) } } written += t2pWriteFile(output, (tdata_t) "] \n/Count ", 10); - buflen=snprintf(buffer, sizeof(buffer), "%d", t2p->tiff_pagecount); + _TIFFmemset(buffer, 0x00, 16); + buflen=sprintf(buffer, "%d", t2p->tiff_pagecount); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " \n>> \n", 6); @@ -4242,28 +4136,28 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ unsigned int i=0; tsize_t written=0; - char buffer[256]; + char buffer[16]; int buflen=0; written += t2pWriteFile(output, (tdata_t) "<<\n/Type /Page \n/Parent ", 24); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_pages); + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_pages); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6); written += t2pWriteFile(output, (tdata_t) "/MediaBox [", 11); - buflen=snprintf(buffer, sizeof(buffer), "%.4f",t2p->pdf_mediabox.x1); + buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.x1); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " ", 1); - buflen=snprintf(buffer, sizeof(buffer), "%.4f",t2p->pdf_mediabox.y1); + buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.y1); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " ", 1); - buflen=snprintf(buffer, sizeof(buffer), "%.4f",t2p->pdf_mediabox.x2); + buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.x2); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " ", 1); - buflen=snprintf(buffer, sizeof(buffer), "%.4f",t2p->pdf_mediabox.y2); + buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.y2); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "] \n", 3); written += t2pWriteFile(output, (tdata_t) "/Contents ", 10); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)(object + 1)); + buflen=sprintf(buffer, "%lu", (unsigned long)(object + 1)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6); written += t2pWriteFile(output, (tdata_t) "/Resources << \n", 15); @@ -4271,13 +4165,15 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ written += t2pWriteFile(output, (tdata_t) "/XObject <<\n", 12); for(i=0;itiff_tiles[t2p->pdf_page].tiles_tilecount;i++){ written += t2pWriteFile(output, (tdata_t) "/Im", 3); - buflen = snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_page+1); + buflen = sprintf(buffer, "%u", t2p->pdf_page+1); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "_", 1); - buflen = snprintf(buffer, sizeof(buffer), "%u", i+1); + buflen = sprintf(buffer, "%u", i+1); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " ", 1); - buflen = snprintf(buffer, sizeof(buffer), "%lu", + buflen = sprintf( + buffer, + "%lu", (unsigned long)(object+3+(2*i)+t2p->tiff_pages[t2p->pdf_page].page_extra)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); @@ -4289,10 +4185,12 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ } else { written += t2pWriteFile(output, (tdata_t) "/XObject <<\n", 12); written += t2pWriteFile(output, (tdata_t) "/Im", 3); - buflen = snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_page+1); + buflen = sprintf(buffer, "%u", t2p->pdf_page+1); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " ", 1); - buflen = snprintf(buffer, sizeof(buffer), "%lu", + buflen = sprintf( + buffer, + "%lu", (unsigned long)(object+3+(2*i)+t2p->tiff_pages[t2p->pdf_page].page_extra)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); @@ -4301,7 +4199,9 @@ tsize_t t2p_write_pdf_page(uint32 object, T2P* t2p, TIFF* output){ if(t2p->tiff_transferfunctioncount != 0) { written += t2pWriteFile(output, (tdata_t) "/ExtGState <<", 13); t2pWriteFile(output, (tdata_t) "/GS1 ", 5); - buflen = snprintf(buffer, sizeof(buffer), "%lu", + buflen = sprintf( + buffer, + "%lu", (unsigned long)(object + 3)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); @@ -4662,7 +4562,7 @@ tsize_t t2p_write_pdf_page_content_stream(T2P* t2p, TIFF* output){ if(t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount>0){ for(i=0;itiff_tiles[t2p->pdf_page].tiles_tilecount; i++){ box=t2p->tiff_tiles[t2p->pdf_page].tiles_tiles[i].tile_box; - buflen=snprintf(buffer, sizeof(buffer), + buflen=sprintf(buffer, "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d_%ld Do Q\n", t2p->tiff_transferfunctioncount?"/GS1 gs ":"", box.mat[0], @@ -4677,7 +4577,7 @@ tsize_t t2p_write_pdf_page_content_stream(T2P* t2p, TIFF* output){ } } else { box=t2p->pdf_imagebox; - buflen=snprintf(buffer, sizeof(buffer), + buflen=sprintf(buffer, "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d Do Q\n", t2p->tiff_transferfunctioncount?"/GS1 gs ":"", box.mat[0], @@ -4702,48 +4602,59 @@ tsize_t t2p_write_pdf_xobject_stream_dict(ttile_t tile, TIFF* output){ tsize_t written=0; - char buffer[32]; + char buffer[16]; int buflen=0; written += t2p_write_pdf_stream_dict(0, t2p->pdf_xrefcount+1, output); written += t2pWriteFile(output, (tdata_t) "/Type /XObject \n/Subtype /Image \n/Name /Im", 42); - buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_page+1); + buflen=sprintf(buffer, "%u", t2p->pdf_page+1); written += t2pWriteFile(output, (tdata_t) buffer, buflen); if(tile != 0){ written += t2pWriteFile(output, (tdata_t) "_", 1); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)tile); + buflen=sprintf(buffer, "%lu", (unsigned long)tile); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } written += t2pWriteFile(output, (tdata_t) "\n/Width ", 8); + _TIFFmemset((tdata_t)buffer, 0x00, 16); if(tile==0){ - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->tiff_width); + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->tiff_width); } else { if(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)!=0){ - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf( + buffer, + "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth); } else { - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf( + buffer, + "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth); } } written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "\n/Height ", 9); + _TIFFmemset((tdata_t)buffer, 0x00, 16); if(tile==0){ - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->tiff_length); + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->tiff_length); } else { if(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)!=0){ - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf( + buffer, + "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength); } else { - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf( + buffer, + "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength); } } written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "\n/BitsPerComponent ", 19); - buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->tiff_bitspersample); + _TIFFmemset((tdata_t)buffer, 0x00, 16); + buflen=sprintf(buffer, "%u", t2p->tiff_bitspersample); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "\n/ColorSpace ", 13); written += t2p_write_pdf_xobject_cs(t2p, output); @@ -4771,7 +4682,7 @@ tsize_t t2p_write_pdf_xobject_stream_dict(ttile_t tile, tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){ tsize_t written=0; - char buffer[256]; + char buffer[128]; int buflen=0; float X_W=1.0; @@ -4787,10 +4698,11 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){ t2p->pdf_colorspace ^= T2P_CS_PALETTE; written += t2p_write_pdf_xobject_cs(t2p, output); t2p->pdf_colorspace |= T2P_CS_PALETTE; - buflen=snprintf(buffer, sizeof(buffer), "%u", (0x0001 << t2p->tiff_bitspersample)-1 ); + buflen=sprintf(buffer, "%u", (0x0001 << t2p->tiff_bitspersample)-1 ); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " ", 1); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_palettecs ); + _TIFFmemset(buffer, 0x00, 16); + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_palettecs ); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ]\n", 7); return(written); @@ -4824,7 +4736,7 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){ X_W /= Y_W; Z_W /= Y_W; Y_W = 1.0F; - buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); + buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); written += t2pWriteFile(output, (tdata_t) buffer, buflen); X_W = 0.3457F; /* 0.3127F; */ /* D50, commented D65 */ Y_W = 0.3585F; /* 0.3290F; */ @@ -4832,10 +4744,10 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){ X_W /= Y_W; Z_W /= Y_W; Y_W = 1.0F; - buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); + buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "/Range ", 7); - buflen=snprintf(buffer, sizeof(buffer), "[%d %d %d %d] \n", + buflen=sprintf(buffer, "[%d %d %d %d] \n", t2p->pdf_labrange[0], t2p->pdf_labrange[1], t2p->pdf_labrange[2], @@ -4851,26 +4763,26 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){ tsize_t t2p_write_pdf_transfer(T2P* t2p, TIFF* output){ tsize_t written=0; - char buffer[32]; + char buffer[16]; int buflen=0; written += t2pWriteFile(output, (tdata_t) "<< /Type /ExtGState \n/TR ", 25); if(t2p->tiff_transferfunctioncount == 1){ - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 1)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); } else { written += t2pWriteFile(output, (tdata_t) "[ ", 2); - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 1)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 2)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 3)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); @@ -4892,7 +4804,7 @@ tsize_t t2p_write_pdf_transfer_dict(T2P* t2p, TIFF* output, uint16 i){ written += t2pWriteFile(output, (tdata_t) "/FunctionType 0 \n", 17); written += t2pWriteFile(output, (tdata_t) "/Domain [0.0 1.0] \n", 19); written += t2pWriteFile(output, (tdata_t) "/Range [0.0 1.0] \n", 18); - buflen=snprintf(buffer, sizeof(buffer), "/Size [%u] \n", (1<tiff_bitspersample)); + buflen=sprintf(buffer, "/Size [%u] \n", (1<tiff_bitspersample)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "/BitsPerSample 16 \n", 19); written += t2p_write_pdf_stream_dict(1<<(t2p->tiff_bitspersample+1), 0, output); @@ -4919,7 +4831,7 @@ tsize_t t2p_write_pdf_transfer_stream(T2P* t2p, TIFF* output, uint16 i){ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){ tsize_t written=0; - char buffer[256]; + char buffer[128]; int buflen=0; float X_W=0.0; @@ -4987,16 +4899,16 @@ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){ written += t2pWriteFile(output, (tdata_t) "<< \n", 4); if(t2p->pdf_colorspace & T2P_CS_CALGRAY){ written += t2pWriteFile(output, (tdata_t) "/WhitePoint ", 12); - buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); + buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "/Gamma 2.2 \n", 12); } if(t2p->pdf_colorspace & T2P_CS_CALRGB){ written += t2pWriteFile(output, (tdata_t) "/WhitePoint ", 12); - buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); + buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "/Matrix ", 8); - buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f] \n", + buflen=sprintf(buffer, "[%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f] \n", X_R, Y_R, Z_R, X_G, Y_G, Z_G, X_B, Y_B, Z_B); @@ -5015,11 +4927,11 @@ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){ tsize_t t2p_write_pdf_xobject_icccs(T2P* t2p, TIFF* output){ tsize_t written=0; - char buffer[32]; + char buffer[16]; int buflen=0; written += t2pWriteFile(output, (tdata_t) "[/ICCBased ", 11); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_icccs); + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_icccs); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " 0 R] \n", 7); @@ -5029,11 +4941,11 @@ tsize_t t2p_write_pdf_xobject_icccs(T2P* t2p, TIFF* output){ tsize_t t2p_write_pdf_xobject_icccs_dict(T2P* t2p, TIFF* output){ tsize_t written=0; - char buffer[32]; + char buffer[16]; int buflen=0; written += t2pWriteFile(output, (tdata_t) "/N ", 3); - buflen=snprintf(buffer, sizeof(buffer), "%u \n", t2p->tiff_samplesperpixel); + buflen=sprintf(buffer, "%u \n", t2p->tiff_samplesperpixel); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) "/Alternate ", 11); t2p->pdf_colorspace ^= T2P_CS_ICCBASED; @@ -5098,7 +5010,7 @@ tsize_t t2p_write_pdf_xobject_decode(T2P* t2p, TIFF* output){ tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t tile, T2P* t2p, TIFF* output){ tsize_t written=0; - char buffer[32]; + char buffer[16]; int buflen=0; if(t2p->pdf_compression==T2P_COMPRESS_NONE){ @@ -5113,33 +5025,41 @@ tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t tile, T2P* t2p, TIFF* output written += t2pWriteFile(output, (tdata_t) "<< /K -1 ", 9); if(tile==0){ written += t2pWriteFile(output, (tdata_t) "/Columns ", 9); - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->tiff_width); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " /Rows ", 7); - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->tiff_length); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } else { if(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)==0){ written += t2pWriteFile(output, (tdata_t) "/Columns ", 9); - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf( + buffer, + "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } else { written += t2pWriteFile(output, (tdata_t) "/Columns ", 9); - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf( + buffer, + "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } if(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)==0){ written += t2pWriteFile(output, (tdata_t) " /Rows ", 7); - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf( + buffer, + "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } else { written += t2pWriteFile(output, (tdata_t) " /Rows ", 7); - buflen=snprintf(buffer, sizeof(buffer), "%lu", + buflen=sprintf( + buffer, + "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength); written += t2pWriteFile(output, (tdata_t) buffer, buflen); } @@ -5166,17 +5086,21 @@ tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t tile, T2P* t2p, TIFF* output if(t2p->pdf_compressionquality%100){ written += t2pWriteFile(output, (tdata_t) "/DecodeParms ", 13); written += t2pWriteFile(output, (tdata_t) "<< /Predictor ", 14); - buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->pdf_compressionquality%100); + _TIFFmemset(buffer, 0x00, 16); + buflen=sprintf(buffer, "%u", t2p->pdf_compressionquality%100); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " /Columns ", 10); - buflen = snprintf(buffer, sizeof(buffer), "%lu", + _TIFFmemset(buffer, 0x00, 16); + buflen = sprintf(buffer, "%lu", (unsigned long)t2p->tiff_width); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " /Colors ", 9); - buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->tiff_samplesperpixel); + _TIFFmemset(buffer, 0x00, 16); + buflen=sprintf(buffer, "%u", t2p->tiff_samplesperpixel); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " /BitsPerComponent ", 19); - buflen=snprintf(buffer, sizeof(buffer), "%u", t2p->tiff_bitspersample); + _TIFFmemset(buffer, 0x00, 16); + buflen=sprintf(buffer, "%u", t2p->tiff_bitspersample); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) ">>\n", 3); } @@ -5196,16 +5120,16 @@ tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t tile, T2P* t2p, TIFF* output tsize_t t2p_write_pdf_xreftable(T2P* t2p, TIFF* output){ tsize_t written=0; - char buffer[64]; + char buffer[21]; int buflen=0; uint32 i=0; written += t2pWriteFile(output, (tdata_t) "xref\n0 ", 7); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)(t2p->pdf_xrefcount + 1)); + buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 1)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) " \n0000000000 65535 f \n", 22); for (i=0;ipdf_xrefcount;i++){ - snprintf(buffer, sizeof(buffer), "%.10lu 00000 n \n", + sprintf(buffer, "%.10lu 00000 n \n", (unsigned long)t2p->pdf_xrefoffsets[i]); written += t2pWriteFile(output, (tdata_t) buffer, 20); } @@ -5245,21 +5169,25 @@ tsize_t t2p_write_pdf_trailer(T2P* t2p, TIFF* output) "%.2hhX", fileidbuf[i]); } written += t2pWriteFile(output, (tdata_t) "trailer\n<<\n/Size ", 17); - buflen = snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)(t2p->pdf_xrefcount+1)); + buflen = sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount+1)); written += t2pWriteFile(output, (tdata_t) buffer, buflen); + _TIFFmemset(buffer, 0x00, 32); written += t2pWriteFile(output, (tdata_t) "\n/Root ", 7); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_catalog); + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_catalog); written += t2pWriteFile(output, (tdata_t) buffer, buflen); + _TIFFmemset(buffer, 0x00, 32); written += t2pWriteFile(output, (tdata_t) " 0 R \n/Info ", 12); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_info); + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_info); written += t2pWriteFile(output, (tdata_t) buffer, buflen); + _TIFFmemset(buffer, 0x00, 32); written += t2pWriteFile(output, (tdata_t) " 0 R \n/ID[<", 11); written += t2pWriteFile(output, (tdata_t) t2p->pdf_fileid, 32); written += t2pWriteFile(output, (tdata_t) "><", 2); written += t2pWriteFile(output, (tdata_t) t2p->pdf_fileid, 32); written += t2pWriteFile(output, (tdata_t) ">]\n>>\nstartxref\n", 16); - buflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_startxref); + buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_startxref); written += t2pWriteFile(output, (tdata_t) buffer, buflen); + _TIFFmemset(buffer, 0x00, 32); written += t2pWriteFile(output, (tdata_t) "\n%%EOF\n", 7); return(written); @@ -5320,7 +5248,6 @@ tsize_t t2p_write_pdf(T2P* t2p, TIFF* input, TIFF* output){ TIFF2PDF_MODULE, "Can't allocate %u bytes of memory for t2p_write_pdf", t2p->pdf_xrefcount * sizeof(uint32) ); - t2p->t2p_error = T2P_ERR_ERROR; return(written); } t2p->pdf_xrefcount=0; diff --git a/tools/tiff2ps.c b/tools/tiff2ps.c index 757da92..e16aa7f 100644 --- a/tools/tiff2ps.c +++ b/tools/tiff2ps.c @@ -1079,8 +1079,8 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) imageOp = "imagemask"; (void)strcpy(im_x, "0"); - (void)snprintf(im_y, sizeof(im_y), "%lu", (long) h); - (void)snprintf(im_h, sizeof(im_h), "%lu", (long) h); + (void)sprintf(im_y, "%lu", (long) h); + (void)sprintf(im_h, "%lu", (long) h); tile_width = w; tile_height = h; if (TIFFIsTiled(tif)) { @@ -1101,7 +1101,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) } if (tile_height < h) { fputs("/im_y 0 def\n", fd); - (void)snprintf(im_y, sizeof(im_y), "%lu im_y sub", (unsigned long) h); + (void)sprintf(im_y, "%lu im_y sub", (unsigned long) h); } } else { repeat_count = tf_numberstrips; @@ -1113,7 +1113,7 @@ PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) fprintf(fd, "/im_h %lu def\n", (unsigned long) tile_height); (void)strcpy(im_h, "im_h"); - (void)snprintf(im_y, sizeof(im_y), "%lu im_y sub", (unsigned long) h); + (void)sprintf(im_y, "%lu im_y sub", (unsigned long) h); } } diff --git a/tools/tiffcp.c b/tools/tiffcp.c index a54e65d..48319fa 100644 --- a/tools/tiffcp.c +++ b/tools/tiffcp.c @@ -1191,14 +1191,10 @@ DECLAREreadFunc(readSeparateStripsIntoBuffer) { int status = 1; tsize_t scanlinesize = TIFFScanlineSize(in); - tdata_t scanline; + tdata_t scanline = _TIFFmalloc(scanlinesize); if (!scanlinesize) return 0; - scanline = _TIFFmalloc(scanlinesize); - if (!scanline) - return 0; - (void) imagewidth; if (scanline) { uint8* bufp = (uint8*) buf; diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c index a5d0231..fa057c5 100644 --- a/tools/tiffcrop.c +++ b/tools/tiffcrop.c @@ -2063,7 +2063,7 @@ update_output_file (TIFF **tiffout, char *mode, int autoindex, strncpy (export_ext, ".tiff", 5); export_ext[5] = '\0'; - snprintf(filenum, sizeof(filenum), "-%03d%s", findex, export_ext); + sprintf (filenum, "-%03d%s", findex, export_ext); filenum[15] = '\0'; strncat (exportname, filenum, 14); } @@ -2213,8 +2213,7 @@ main(int argc, char* argv[]) if (dump.infile != NULL) fclose (dump.infile); - snprintf(temp_filename, sizeof(temp_filename), "%s-read-%03d.%s", - dump.infilename, dump_images, + sprintf (temp_filename, "%s-read-%03d.%s", dump.infilename, dump_images, (dump.format == DUMP_TEXT) ? "txt" : "raw"); if ((dump.infile = fopen(temp_filename, dump.mode)) == NULL) { @@ -2230,8 +2229,7 @@ main(int argc, char* argv[]) if (dump.outfile != NULL) fclose (dump.outfile); - snprintf(temp_filename, sizeof(temp_filename), "%s-write-%03d.%s", - dump.outfilename, dump_images, + sprintf (temp_filename, "%s-write-%03d.%s", dump.outfilename, dump_images, (dump.format == DUMP_TEXT) ? "txt" : "raw"); if ((dump.outfile = fopen(temp_filename, dump.mode)) == NULL) { @@ -2576,7 +2574,6 @@ static void dump_info(FILE *dumpfile, int format, char *prefix, char *msg, ...) fprintf(dumpfile, "%s ", prefix); vfprintf(dumpfile, msg, ap); fprintf(dumpfile, "\n"); - va_end(ap); } } diff --git a/tools/tiffdither.c b/tools/tiffdither.c index 5ceb314..dee2a02 100644 --- a/tools/tiffdither.c +++ b/tools/tiffdither.c @@ -77,7 +77,7 @@ fsdither(TIFF* in, TIFF* out) * Get first line */ if (TIFFReadScanline(in, inputline, 0, 0) <= 0) - goto skip_on_error; + return; inptr = inputline; nextptr = nextline; for (j = 0; j < imagewidth; ++j) @@ -128,7 +128,6 @@ fsdither(TIFF* in, TIFF* out) if (TIFFWriteScanline(out, outline, i-1, 0) < 0) break; } -skip_on_error: _TIFFfree(inputline); _TIFFfree(thisline); _TIFFfree(nextline); @@ -257,7 +256,7 @@ main(int argc, char* argv[]) TIFFSetField(out, TIFFTAG_FILLORDER, fillorder); else CopyField(TIFFTAG_FILLORDER, shortv); - snprintf(thing, sizeof(thing), "Dithered B&W version of %s", argv[optind]); + sprintf(thing, "Dithered B&W version of %s", argv[optind]); TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, thing); CopyField(TIFFTAG_PHOTOMETRIC, shortv); CopyField(TIFFTAG_ORIENTATION, shortv); diff --git a/tools/tiffdump.c b/tools/tiffdump.c index 58989a1..5161189 100644 --- a/tools/tiffdump.c +++ b/tools/tiffdump.c @@ -46,7 +46,6 @@ # include #endif -#include "tiffiop.h" #include "tiffio.h" #ifndef O_BINARY @@ -318,7 +317,7 @@ ReadDirectory(int fd, unsigned ix, off_t off) printf(">\n"); continue; } - space = TIFFSafeMultiply(int, dp->tdir_count, datawidth[dp->tdir_type]); + space = dp->tdir_count * datawidth[dp->tdir_type]; if (space <= 0) { printf(">\n"); Error("Invalid count for tag %u", dp->tdir_tag); @@ -710,7 +709,7 @@ TIFFFetchData(int fd, TIFFDirEntry* dir, void* cp) w = (dir->tdir_type < NWIDTHS ? datawidth[dir->tdir_type] : 0); cc = dir->tdir_count * w; if (lseek(fd, (off_t)dir->tdir_offset, 0) != (off_t)-1 - && read(fd, cp, cc) == cc) { + && read(fd, cp, cc) != -1) { if (swabflag) { switch (dir->tdir_type) { case TIFF_SHORT: diff --git a/tools/tiffinfo.c b/tools/tiffinfo.c index 95c094e..4d4ae64 100644 --- a/tools/tiffinfo.c +++ b/tools/tiffinfo.c @@ -49,7 +49,7 @@ int readdata = 0; /* read data in file */ int stoponerr = 1; /* stop on first read error */ static void usage(void); -static void tiffinfo(TIFF*, uint16, long, int); +static void tiffinfo(TIFF*, uint16, long); int main(int argc, char* argv[]) @@ -124,20 +124,19 @@ main(int argc, char* argv[]) if (tif != NULL) { if (dirnum != -1) { if (TIFFSetDirectory(tif, (tdir_t) dirnum)) - tiffinfo(tif, order, flags, 1); + tiffinfo(tif, order, flags); } else if (diroff != 0) { if (TIFFSetSubDirectory(tif, diroff)) - tiffinfo(tif, order, flags, 1); + tiffinfo(tif, order, flags); } else { do { uint32 offset; - tiffinfo(tif, order, flags, 1); + tiffinfo(tif, order, flags); if (TIFFGetField(tif, TIFFTAG_EXIFIFD, &offset)) { - if (TIFFReadEXIFDirectory(tif, offset)) { - tiffinfo(tif, order, flags, 0); - } + if (TIFFReadEXIFDirectory(tif, offset)) + tiffinfo(tif, order, flags); } } while (TIFFReadDirectory(tif)); } @@ -427,10 +426,10 @@ TIFFReadRawData(TIFF* tif, int bitrev) } static void -tiffinfo(TIFF* tif, uint16 order, long flags, int is_image) +tiffinfo(TIFF* tif, uint16 order, long flags) { TIFFPrintDirectory(tif, stdout, flags); - if (!readdata || !is_image) + if (!readdata) return; if (rawdata) { if (order) { diff --git a/tools/tiffsplit.c b/tools/tiffsplit.c index 03b5558..58288cd 100644 --- a/tools/tiffsplit.c +++ b/tools/tiffsplit.c @@ -237,11 +237,7 @@ cpStrips(TIFF* in, TIFF* out) tstrip_t s, ns = TIFFNumberOfStrips(in); uint32 *bytecounts; - if (!TIFFGetField(in, TIFFTAG_STRIPBYTECOUNTS, &bytecounts)) { - fprintf(stderr, "tiffsplit: strip byte counts are missing\n"); - _TIFFfree(buf); - return (0); - } + TIFFGetField(in, TIFFTAG_STRIPBYTECOUNTS, &bytecounts); for (s = 0; s < ns; s++) { if (bytecounts[s] > (uint32)bufsize) { buf = (unsigned char *)_TIFFrealloc(buf, bytecounts[s]); @@ -271,11 +267,7 @@ cpTiles(TIFF* in, TIFF* out) ttile_t t, nt = TIFFNumberOfTiles(in); uint32 *bytecounts; - if (!TIFFGetField(in, TIFFTAG_TILEBYTECOUNTS, &bytecounts)) { - fprintf(stderr, "tiffsplit: tile byte counts are missing\n"); - _TIFFfree(buf); - return (0); - } + TIFFGetField(in, TIFFTAG_TILEBYTECOUNTS, &bytecounts); for (t = 0; t < nt; t++) { if (bytecounts[t] > (uint32) bufsize) { buf = (unsigned char *)_TIFFrealloc(buf, bytecounts[t]);