diff options
author | Marti Maria <marti.maria@littlecms.com> | 2020-04-24 14:30:20 +0200 |
---|---|---|
committer | Marti Maria <marti.maria@littlecms.com> | 2020-04-24 14:30:20 +0200 |
commit | dd62fa432af879d127f0014b7d96246841ad96f7 (patch) | |
tree | 5145cd96853c6fd5f28fa082b555995423e15fc2 /utils | |
parent | aa64fa73c26bfb61b087ac1dab5cf44b53f57b24 (diff) | |
download | lcms2-dd62fa432af879d127f0014b7d96246841ad96f7.tar.gz |
Update tifficc.c to remove VS 2019 warnings
It also detects wrong TIFF with strips too big (more than MAX_INT)
Diffstat (limited to 'utils')
-rw-r--r-- | utils/tificc/tificc.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/utils/tificc/tificc.c b/utils/tificc/tificc.c index 069cc42..3973bc3 100644 --- a/utils/tificc/tificc.c +++ b/utils/tificc/tificc.c @@ -385,16 +385,20 @@ int TileBasedXform(cmsHTRANSFORM hXForm, TIFF* in, TIFF* out, int nPlanes) int PixelCount, j; + // Check for bad tiffs + if (BufSizeIn > INT_MAX || BufSizeOut > INT_MAX) + FatalError("Probably corrupted TIFF, tile too big."); + TIFFGetFieldDefaulted(in, TIFFTAG_TILEWIDTH, &tw); TIFFGetFieldDefaulted(in, TIFFTAG_TILELENGTH, &tl); PixelCount = (int) tw * tl; BufferIn = (unsigned char *) _TIFFmalloc(BufSizeIn * nPlanes); - if (!BufferIn) OutOfMem(BufSizeIn * nPlanes); + if (!BufferIn) OutOfMem((cmsUInt32Number) BufSizeIn * nPlanes); BufferOut = (unsigned char *) _TIFFmalloc(BufSizeOut * nPlanes); - if (!BufferOut) OutOfMem(BufSizeOut * nPlanes); + if (!BufferOut) OutOfMem((cmsUInt32Number) BufSizeOut * nPlanes); for (i = 0; i < TileCount; i++) { @@ -443,6 +447,10 @@ int StripBasedXform(cmsHTRANSFORM hXForm, TIFF* in, TIFF* out, int nPlanes) int j; int PixelCount; + // Check for bad tiffs + if (BufSizeIn > INT_MAX || BufSizeOut > INT_MAX) + FatalError("Probably corrupted TIFF, strip too big."); + TIFFGetFieldDefaulted(in, TIFFTAG_IMAGEWIDTH, &sw); TIFFGetFieldDefaulted(in, TIFFTAG_ROWSPERSTRIP, &sl); TIFFGetFieldDefaulted(in, TIFFTAG_IMAGELENGTH, &iml); @@ -452,10 +460,10 @@ int StripBasedXform(cmsHTRANSFORM hXForm, TIFF* in, TIFF* out, int nPlanes) sl = iml; // One strip for whole image BufferIn = (unsigned char *) _TIFFmalloc(BufSizeIn * nPlanes); - if (!BufferIn) OutOfMem(BufSizeIn * nPlanes); + if (!BufferIn) OutOfMem((cmsUInt32Number) BufSizeIn * nPlanes); BufferOut = (unsigned char *) _TIFFmalloc(BufSizeOut * nPlanes); - if (!BufferOut) OutOfMem(BufSizeOut * nPlanes); + if (!BufferOut) OutOfMem((cmsUInt32Number) BufSizeOut * nPlanes); for (i = 0; i < StripCount; i++) { @@ -667,7 +675,7 @@ void DoEmbedProfile(TIFF* Out, const char* ProfileFile) size = cmsfilelength(f); if (size < 0) return; - EmbedBuffer = (cmsUInt8Number*) malloc(size + 1); + EmbedBuffer = (cmsUInt8Number*) malloc((size_t) size + 1); if (EmbedBuffer == NULL) { OutOfMem(size+1); return; @@ -675,7 +683,7 @@ void DoEmbedProfile(TIFF* Out, const char* ProfileFile) EmbedLen = (cmsUInt32Number) fread(EmbedBuffer, 1, (size_t) size, f); - if (EmbedLen != size) + if (EmbedLen != (cmsUInt32Number) size) FatalError("Cannot read %ld bytes to %s", size, ProfileFile); fclose(f); |