Skip to content

Commit c22dc86

Browse files
committed
Add an extra check in an undocumented function.
Add a guard for a theoretical abuse although in practice cannot be exploited at all. For completeness sake. Thanks to @parasol-aser for reporting and providing the fix.
1 parent 704896b commit c22dc86

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

src/cmsps2.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,32 @@ char* RemoveCR(const char* txt)
329329

330330
}
331331

332+
// Writes the body of a PostScript string literal, escaping the metacharacters
333+
// '\\', '(' and ')' and emitting non-printable / high-bit bytes as octal
334+
// triples per PLRM 3.3.4.1. The caller is responsible for the surrounding
335+
// '(' and ')' delimiters.
336+
static
337+
void EmitPSEscaped(cmsIOHANDLER* m, const char* txt)
338+
{
339+
const unsigned char* p;
340+
341+
if (txt == NULL) return;
342+
343+
for (p = (const unsigned char*)txt; *p != 0; p++) {
344+
unsigned char c = *p;
345+
346+
if (c == '\\' || c == '(' || c == ')') {
347+
_cmsIOPrintf(m, "\\%c", c);
348+
}
349+
else if (c < 0x20 || c >= 0x7F) {
350+
_cmsIOPrintf(m, "\\%03o", c);
351+
}
352+
else {
353+
_cmsIOPrintf(m, "%c", c);
354+
}
355+
}
356+
}
357+
332358
static
333359
void EmitHeader(cmsIOHANDLER* m, const char* Title, cmsHPROFILE hProfile)
334360
{
@@ -1019,7 +1045,10 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, cmsUInt32Number
10191045
continue;
10201046

10211047
cmsDoTransform(xform, In, &Lab, 1);
1022-
_cmsIOPrintf(m, " (%s) [ %.3f %.3f %.3f ]\n", ColorName, Lab.L, Lab.a, Lab.b);
1048+
1049+
_cmsIOPrintf(m, " (");
1050+
EmitPSEscaped(m, ColorName);
1051+
_cmsIOPrintf(m, ") [ %.3f %.3f %.3f ]\n", Lab.L, Lab.a, Lab.b);
10231052
}
10241053

10251054
_cmsIOPrintf(m, ">>\n");
@@ -1454,7 +1483,10 @@ int WriteNamedColorCRD(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, cmsUInt32Number
14541483

14551484
cmsDoTransform(xform, In, Out, 1);
14561485
BuildColorantList(Colorant, nColorant, Out);
1457-
_cmsIOPrintf(m, " (%s) [ %s ]\n", ColorName, Colorant);
1486+
1487+
_cmsIOPrintf(m, " (");
1488+
EmitPSEscaped(m, ColorName);
1489+
_cmsIOPrintf(m, ") [ %s ]\n", Colorant);
14581490
}
14591491

14601492
_cmsIOPrintf(m, " >>");

0 commit comments

Comments
 (0)