Add a pixel test for JPX images with mismatched color spaces

Add a pixel test that contains 6 JPX images on a gray background. Each
image's color space type doesn't match the "/ColorSpace" entry in their
image object.

Currently these images can either cause crash or be rendered
incorrectly. The correct expectation is a gray background and none of
the images should be rendered.

Bug: chromium:1429465
Change-Id: I84bfae7e655ac569d113fd0ea14b6cedf645219b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/105910
Commit-Queue: Nigi <nigi@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS
index b50d3ce..9dfa35f 100644
--- a/testing/SUPPRESSIONS
+++ b/testing/SUPPRESSIONS
@@ -384,6 +384,7 @@
 jpxdecode.in * * * *
 jpxdecode_without_bitspercomponent.in * * * *
 jpxdecode_without_colorspace.in * * * *
+jpxdecode_with_mismatch_colorspace.in * * * *
 
 # TODO(chromium:1028991): Remove after associated bug is fixed
 reset_button.in * * * *
diff --git a/testing/resources/pixel/jpxdecode_with_mismatch_colorspace.in b/testing/resources/pixel/jpxdecode_with_mismatch_colorspace.in
new file mode 100644
index 0000000..ddf3068
--- /dev/null
+++ b/testing/resources/pixel/jpxdecode_with_mismatch_colorspace.in
@@ -0,0 +1,180 @@
+{{header}}
+{{object 1 0}} <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+{{object 2 0}} <<
+  /Type /Pages
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+{{object 3 0}} <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+  /MediaBox [0 0 88 128]
+  /Resources <<
+    /XObject <<
+      /ImGrayCsRGB 5 0 R
+      /ImGrayCsCMYK 6 0 R
+      /ImRGBCsGray 7 0 R
+      /ImRGBCsCMYK 8 0 R
+      /ImCMYKCsGray 9 0 R
+      /ImCMYKCsRGB 10 0 R
+    >>
+  >>
+>>
+endobj
+{{object 4 0}} <<
+  {{streamlen}}
+>>
+stream
+
+% 50% gray background rectangle
+q
+  0.5 0.5 0.5 rg
+  0 0 88 128 re
+  f
+Q
+
+% grayscale image with RGB /ColorSpace entry
+q
+  32 0 0 32 8 88 cm
+  /ImGrayCsRGB Do
+Q
+
+% grayscale image with CMYK /ColorSpace entry
+q
+  32 0 0 32 48 88 cm
+  /ImGrayCsCMYK Do
+Q
+
+% RGB image with grayscale /ColorSpace entry
+q
+  32 0 0 32 8 48 cm
+  /ImRGBCsGray Do
+Q
+
+% RGB image with CMYK /ColorSpace entry
+q
+  32 0 0 32 48 48 cm
+  /ImRGBCsCMYK Do
+Q
+
+% CMYK image with grayscale /ColorSpace entry
+q
+  32 0 0 32 8 8 cm
+  /ImCMYKCsGray Do
+Q
+
+% CMYK image with RGB /ColorSpace entry
+q
+  32 0 0 32 48 8 cm
+  /ImCMYKCsRGB Do
+Q
+
+endstream
+endobj
+
+% grayscale image with RGB /ColorSpace
+{{object 5 0}} <<
+  /Type /XObject
+  /Subtype /Image
+  /BitsPerComponent 8
+  /ColorSpace /DeviceRGB
+  /Filter /JPXDecode
+  /Height 4
+  /Width 4
+  {{streamlen}}
+>>
+stream
+{{include ../gray.jp2}}
+endstream
+endobj
+
+% grayscale image with CMYK /ColorSpace
+{{object 6 0}} <<
+  /Type /XObject
+  /Subtype /Image
+  /BitsPerComponent 8
+  /ColorSpace /DeviceCMYK
+  /Filter /JPXDecode
+  /Height 4
+  /Width 4
+  {{streamlen}}
+>>
+stream
+{{include ../gray.jp2}}
+endstream
+endobj
+
+% RGB image with grayscale /ColorSpace
+{{object 7 0}} <<
+  /Type /XObject
+  /Subtype /Image
+  /BitsPerComponent 8
+  /ColorSpace /DeviceGray
+  /Filter /JPXDecode
+  /Height 4
+  /Width 4
+  {{streamlen}}
+>>
+stream
+{{include ../RGB.jp2}}
+endstream
+endobj
+
+% RGB image with CMYK /ColorSpace
+{{object 8 0}} <<
+  /Type /XObject
+  /Subtype /Image
+  /BitsPerComponent 8
+  /ColorSpace /DeviceCMYK
+  /Filter /JPXDecode
+  /Height 4
+  /Width 4
+  {{streamlen}}
+>>
+stream
+{{include ../RGB.jp2}}
+endstream
+endobj
+
+% CMYK image with grayscale /ColorSpace
+{{object 9 0}} <<
+  /Type /XObject
+  /Subtype /Image
+  /BitsPerComponent 8
+  /ColorSpace /DeviceGray
+  /Filter /JPXDecode
+  /Height 4
+  /Width 4
+  {{streamlen}}
+>>
+stream
+{{include ../CMYK.jpf}}
+endstream
+endobj
+
+% CMYK image with RGB /ColorSpace
+{{object 10 0}} <<
+  /Type /XObject
+  /Subtype /Image
+  /BitsPerComponent 8
+  /ColorSpace /DeviceRGB
+  /Filter /JPXDecode
+  /Height 4
+  /Width 4
+  {{streamlen}}
+>>
+stream
+{{include ../CMYK.jpf}}
+endstream
+endobj
+
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/pixel/jpxdecode_with_mismatch_colorspace_expected.pdf.0.png b/testing/resources/pixel/jpxdecode_with_mismatch_colorspace_expected.pdf.0.png
new file mode 100644
index 0000000..65743e0
--- /dev/null
+++ b/testing/resources/pixel/jpxdecode_with_mismatch_colorspace_expected.pdf.0.png
Binary files differ