Skip to content

Commit e1ab15b

Browse files
committedMar 29, 2024
Correct some coverity issues from "avoid IFD overwriting".
1 parent f46f73b commit e1ab15b

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed
 

‎contrib/addtiffo/tif_overview.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ uint32_t TIFF_WriteOverview(TIFF *hTIFF, uint32_t nXSize, uint32_t nYSize,
149149
if (TIFFWriteCheck(hTIFF, bTiled, "TIFFBuildOverviews") == 0)
150150
return 0;
151151

152-
TIFFWriteDirectory(hTIFF);
152+
if (!TIFFWriteDirectory(hTIFF))
153+
return 0;
153154
iNumDir = TIFFNumberOfDirectories(hTIFF);
154155
if (iNumDir > TIFF_DIR_MAX)
155156
{

‎contrib/iptcutil/iptcutil.c

-3
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ int main(int argc, char *argv[])
446446
int inputlen = BUFFER_SZ;
447447

448448
line = (char *)malloc(inputlen);
449-
token = (char *)NULL;
450449
while ((line = super_fgets(line, &inputlen, ifile)) != NULL)
451450
{
452451
state = 0;
@@ -518,9 +517,7 @@ int main(int argc, char *argv[])
518517
state++;
519518
}
520519
free(token);
521-
token = (char *)NULL;
522520
free(newstr);
523-
newstr = (char *)NULL;
524521
}
525522
free(line);
526523

‎libtiff/tif_dirread.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -4310,7 +4310,7 @@ int TIFFReadDirectory(TIFF *tif)
43104310
TIFFErrorExtR(
43114311
tif, module,
43124312
"Failed to allocate memory for counting IFD data size at reading");
4313-
return 0;
4313+
goto bad;
43144314
}
43154315
/*
43164316
* Electronic Arts writes gray-scale TIFF files
@@ -5279,6 +5279,8 @@ int TIFFReadCustomDirectory(TIFF *tif, toff_t diroff,
52795279
TIFFErrorExtR(
52805280
tif, module,
52815281
"Failed to allocate memory for counting IFD data size at reading");
5282+
if (dir)
5283+
_TIFFfreeExt(tif, dir);
52825284
return 0;
52835285
}
52845286

‎libtiff/tif_dirwrite.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ static int TIFFWriteDirectoryTagIfdIfd8Array(TIFF *tif, uint32_t *ndir,
20142014
static void EvaluateIFDdatasizeWrite(TIFF *tif, uint32_t count,
20152015
uint32_t typesize, uint32_t *ndir)
20162016
{
2017-
uint64_t datalength = count * typesize;
2017+
uint64_t datalength = (uint64_t)count * typesize;
20182018
if (datalength > ((tif->tif_flags & TIFF_BIGTIFF) ? 0x8U : 0x4U))
20192019
{
20202020
/* LibTIFF increments write adress to an even offset, thus datalenght

‎test/rewrite_tag.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ int rewrite_test(const char *filename, uint32_t width, int length, int bigtiff,
255255

256256
upd_bytecount = (uint64_t *)_TIFFmalloc(sizeof(uint64_t) * length);
257257
for (i = 0; i < length; i++)
258-
upd_bytecount[i] = 100 + i * width;
258+
upd_bytecount[i] = 100 + (uint64_t)i * width;
259259

260260
if (!_TIFFRewriteField(tif, TIFFTAG_STRIPBYTECOUNTS, TIFF_LONG8, length,
261261
upd_bytecount))
@@ -308,7 +308,7 @@ int rewrite_test(const char *filename, uint32_t width, int length, int bigtiff,
308308

309309
for (i = 0; i < length; i++)
310310
{
311-
uint64_t expect = 100 + i * width;
311+
uint64_t expect = 100 + (uint64_t)i * width;
312312

313313
if (rowbytes[i] != expect)
314314
{

‎test/test_IFD_enlargement.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ int test_EXIF_enlargement(const char *filename, bool is_big_tiff)
917917
goto failure;
918918
}
919919
/* Set EXIFIFD tag with dummy value to reserve space in IFD. */
920-
if (!TIFFSetField(tif, TIFFTAG_EXIFIFD, 0))
920+
if (!TIFFSetField(tif, TIFFTAG_EXIFIFD, (uint64_t)0))
921921
{
922922
fprintf(stderr, "Can't set TIFFTAG_EXIFIFD tag. Testline %d\n",
923923
__LINE__);

0 commit comments

Comments
 (0)
Please sign in to comment.