From e0268dcc876bb016084967ce5f831099ebec602c Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 20 Oct 2023 11:12:38 -0400 Subject: [PATCH] LibPDF: Allow /Pattern to be used directly as a color space name Per spec: "If the color space is one that can be specified by a name and no additional parameters (DeviceGray, DeviceRGB, DeviceCMYK, and certain cases of Pattern), the name may be specified directly." We still don't implement /Pattern color spaces, but now we no longer crash trying to look up the potentially-nonexistent /ColorSpace dictionary on the page object when /Pattern is used directly as color space name. On top of #21514, reduces number of crashes on 300 random PDFs from the web (the first 300 from 0000.zip from https://pdfa.org/new-large-scale-pdf-corpus-now-publicly-available/) from 42 (14%) to 34 (11%). --- Userland/Libraries/LibPDF/ColorSpace.cpp | 2 ++ Userland/Libraries/LibPDF/ColorSpace.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibPDF/ColorSpace.cpp b/Userland/Libraries/LibPDF/ColorSpace.cpp index 60ffff7d43..b4a46f5426 100644 --- a/Userland/Libraries/LibPDF/ColorSpace.cpp +++ b/Userland/Libraries/LibPDF/ColorSpace.cpp @@ -39,6 +39,8 @@ PDFErrorOr> ColorSpace::create(DeprecatedFlyString con return DeviceRGBColorSpace::the(); if (name == CommonNames::DeviceCMYK) return DeviceCMYKColorSpace::the(); + if (name == CommonNames::Pattern) + return Error::rendering_unsupported_error("Pattern color spaces not yet implemented"); VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibPDF/ColorSpace.h b/Userland/Libraries/LibPDF/ColorSpace.h index 5a01cc5beb..ae4fba0231 100644 --- a/Userland/Libraries/LibPDF/ColorSpace.h +++ b/Userland/Libraries/LibPDF/ColorSpace.h @@ -21,7 +21,7 @@ V(Lab, false) \ V(ICCBased, false) \ V(Indexed, false) \ - V(Pattern, false) \ + V(Pattern, true) \ V(Separation, false) \ V(DeviceN, false)