Skip to content

Commit ce1174b

Browse files
Merge commit from fork
* Fix heap-buffer overflow write in cfImageLut 1. fix for CVE-2025-57812 * Reject color images with 1 bit per sample 2. fix for CVE-2025-57812 * Reject images where the number of samples does not correspond with the color space 3. fix for CVE-2025-57812 * Reject images with planar color configuration 4. fix for CVE-2025-57812 * Reject images with vertical scanlines 5. fix for CVE-2025-57812 --------- Co-authored-by: Till Kamppeter <[email protected]>
1 parent e9fe863 commit ce1174b

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

cupsfilters/image-tiff.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ _cfImageReadTIFF(
4141
TIFF *tif; // TIFF file
4242
uint32_t width, height; // Size of image
4343
uint16_t photometric, // Colorspace
44+
planar, // Color components in separate planes
4445
compression, // Type of compression
4546
orientation, // Orientation
4647
resunit, // Units for resolution
@@ -113,6 +114,15 @@ _cfImageReadTIFF(
113114
return (-1);
114115
}
115116

117+
if (TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planar) &&
118+
planar == PLANARCONFIG_SEPARATE)
119+
{
120+
fputs("DEBUG: Images with planar color configuration are not supported!\n", stderr);
121+
TIFFClose(tif);
122+
fclose(fp);
123+
return (1);
124+
}
125+
116126
if (!TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression))
117127
{
118128
DEBUG_puts("DEBUG: No compression tag in the file!\n");
@@ -127,6 +137,15 @@ _cfImageReadTIFF(
127137
if (!TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bits))
128138
bits = 1;
129139

140+
if (bits == 1 && samples > 1)
141+
{
142+
fprintf(stderr, "ERROR: Color images with 1 bit per sample not supported! "
143+
"Samples per pixel: %d; Bits per sample: %d\n", samples, bits);
144+
TIFFClose(tif);
145+
fclose(fp);
146+
return (1);
147+
}
148+
130149
//
131150
// Get the image orientation...
132151
//
@@ -193,6 +212,23 @@ _cfImageReadTIFF(
193212
else
194213
alpha = 0;
195214

215+
//
216+
// Check whether number of samples per pixel corresponds with color space
217+
//
218+
219+
if ((photometric == PHOTOMETRIC_RGB && (samples < 3 || samples > 4)) ||
220+
(photometric == PHOTOMETRIC_SEPARATED && samples != 4))
221+
{
222+
fprintf(stderr, "DEBUG: Number of samples per pixel does not correspond to color space! "
223+
"Color space: %s; Samples per pixel: %d\n",
224+
(photometric == PHOTOMETRIC_RGB ? "RGB" :
225+
(photometric == PHOTOMETRIC_SEPARATED ? "CMYK" : "Unknown")),
226+
samples);
227+
TIFFClose(tif);
228+
fclose(fp);
229+
return (1);
230+
}
231+
196232
//
197233
// Check the size of the image...
198234
//
@@ -265,6 +301,14 @@ _cfImageReadTIFF(
265301
break;
266302
}
267303

304+
if (orientation >= ORIENTATION_LEFTTOP)
305+
{
306+
fputs("ERROR: TIFF files with vertical scanlines are not supported!\n", stderr);
307+
TIFFClose(tif);
308+
fclose(fp);
309+
return (-1);
310+
}
311+
268312
switch (orientation)
269313
{
270314
case ORIENTATION_TOPRIGHT :
@@ -1493,7 +1537,7 @@ _cfImageReadTIFF(
14931537
}
14941538

14951539
if (lut)
1496-
cfImageLut(out, img->xsize * 3, lut);
1540+
cfImageLut(out, img->xsize * bpp, lut);
14971541

14981542
_cfImagePutRow(img, 0, y, img->xsize, out);
14991543
}

0 commit comments

Comments
 (0)