Browse Source

LibPDF: Implement ICCBasedColorSpace::number_of_components()

We now no longer crash on images that use an ICC-based color space.
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 81 (27%) to 64 (21%).

Also fixes all remaining crashes in
411_getting_started_with_instruments.pdf and
513_high_efficiency_image_file_format.pdf.
Nico Weber 1 year ago
parent
commit
33443f7991

+ 5 - 0
Userland/Libraries/LibPDF/ColorSpace.cpp

@@ -354,6 +354,11 @@ PDFErrorOr<Color> ICCBasedColorSpace::color(Vector<Value> const& arguments) cons
     return Color(output[0], output[1], output[2]);
 }
 
+int ICCBasedColorSpace::number_of_components() const
+{
+    return Gfx::ICC::number_of_components_in_color_space(m_profile->data_color_space());
+}
+
 Vector<float> ICCBasedColorSpace::default_decode() const
 {
     auto color_space = m_profile->data_color_space();

+ 1 - 1
Userland/Libraries/LibPDF/ColorSpace.h

@@ -133,7 +133,7 @@ public:
     ~ICCBasedColorSpace() override = default;
 
     PDFErrorOr<Color> color(Vector<Value> const& arguments) const override;
-    int number_of_components() const override { VERIFY_NOT_REACHED(); }
+    int number_of_components() const override;
     Vector<float> default_decode() const override;
     ColorSpaceFamily const& family() const override { return ColorSpaceFamily::ICCBased; }