Skip to content

Commit ae14d97

Browse files
authored
radload: improve sanity check of colour-related headers (#4384)
Ensure PRIMARIES and COLORCORR have expected number of components
1 parent beddac1 commit ae14d97

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- morph: fix Orc path with large masks [kleisauke]
2222
- invertlut: fix final value in some cases
2323
- matrixload: fix file format detect for some matrix types
24+
- radload: improve sanity check of colour-related headers [lovell]
2425

2526
10/10/24 8.16.0
2627

libvips/foreign/radiance.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ typedef float RGBPRIMS[4][2]; /* (x,y) chromaticities for RGBW */
229229
#define COLCORSTR "COLORCORR="
230230
#define LCOLCORSTR 10
231231
#define iscolcor(hl) (!strncmp(hl, COLCORSTR, LCOLCORSTR))
232-
#define colcorval(cc, hl) sscanf((hl) + LCOLCORSTR, "%f %f %f", \
233-
&(cc)[RED], &(cc)[GRN], &(cc)[BLU])
232+
#define colcorval(cc, hl) (sscanf((hl) + LCOLCORSTR, "%f %f %f", \
233+
&(cc)[RED], &(cc)[GRN], &(cc)[BLU]) == 3)
234234

235235
#define MINELEN 8 /* minimum scanline length for encoding */
236236
#define MAXELEN 0x7fff /* maximum scanline length for encoding */
@@ -643,15 +643,17 @@ rad2vips_process_line(char *line, Read *read)
643643
COLOR cc;
644644
int i;
645645

646-
(void) colcorval(cc, line);
646+
if (!colcorval(cc, line))
647+
return -1;
647648
for (i = 0; i < 3; i++)
648649
read->colcor[i] *= cc[i];
649650
}
650651
else if (isaspect(line)) {
651652
read->aspect *= aspectval(line);
652653
}
653654
else if (isprims(line)) {
654-
(void) primsval(read->prims, line);
655+
if (!primsval(read->prims, line))
656+
return -1;
655657
}
656658

657659
return 0;

0 commit comments

Comments
 (0)