Add a test case for FPDFPage_GenerateContent() not applying color.
This minimal test case demonstrates the bug in question and leaves a
TODO to fix it.
Bug: pdfium:1549
Change-Id: I1ef27ae7bf305e73f94c080031063dc9c6270ae5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/82890
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Hui Yingst <nigi@chromium.org>
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index f16f5d5..44f766e 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -661,6 +661,36 @@
UnloadPage(page);
}
+TEST_F(FPDFEditEmbedderTest, BUG_1549) {
+ static const char kOriginalChecksum[] = "126366fb95e6caf8ea196780075b22b2";
+ static const char kRemovedChecksum[] = "6ec2f27531927882624b37bc7d8e12f4";
+
+ ASSERT_TRUE(OpenDocument("bug_1549.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+
+ {
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ CompareBitmap(bitmap.get(), 100, 150, kOriginalChecksum);
+
+ ScopedFPDFPageObject obj(FPDFPage_GetObject(page, 0));
+ ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj.get()));
+ ASSERT_TRUE(FPDFPage_RemoveObject(page, obj.get()));
+ }
+
+ ASSERT_TRUE(FPDFPage_GenerateContent(page));
+
+ {
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ CompareBitmap(bitmap.get(), 100, 150, kRemovedChecksum);
+ }
+
+ ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
+ UnloadPage(page);
+
+ // TODO(crbug.com/pdfium/1549): Should be `kRemovedChecksum`.
+ VerifySavedDocument(100, 150, "4f9889cd5993db20f1ab37d677ac8d26");
+}
+
TEST_F(FPDFEditEmbedderTest, SetText) {
// Load document with some text.
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
diff --git a/testing/resources/bug_1549.in b/testing/resources/bug_1549.in
new file mode 100644
index 0000000..18285ca
--- /dev/null
+++ b/testing/resources/bug_1549.in
@@ -0,0 +1,63 @@
+{{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
+ /MediaBox [0 0 100 150]
+ /Contents 4 0 R
+ /Resources 5 0 R
+>>
+endobj
+{{object 4 0}} <<
+ {{streamlen}}
+>>
+stream
+q
+20 0 0 20 0 100 cm
+/Im1 Do
+Q
+BT
+/Cs1 cs
+1 0 0 0 scn
+30 20 50 40 re f
+ET
+endstream
+endobj
+{{object 5 0}} <<
+ /ColorSpace <<
+ /Cs1 /DeviceCMYK
+ >>
+ /ProcSet [/PDF /ImageB]
+ /XObject <<
+ /Im1 6 0 R
+ >>
+>>
+endobj
+{{object 6 0}} <<
+ /Type /XObject
+ /Subtype /Image
+ /Width 1
+ /Height 1
+ /BitsPerComponent 8
+ /ColorSpace /DeviceGray
+ /Filter /ASCIIHexDecode
+ {{streamlen}}
+>>
+stream
+33
+endstream
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/bug_1549.pdf b/testing/resources/bug_1549.pdf
new file mode 100644
index 0000000..946ba43
--- /dev/null
+++ b/testing/resources/bug_1549.pdf
@@ -0,0 +1,76 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /Count 1
+ /Kids [3 0 R]
+>>
+endobj
+3 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /MediaBox [0 0 100 150]
+ /Contents 4 0 R
+ /Resources 5 0 R
+>>
+endobj
+4 0 obj <<
+ /Length 74
+>>
+stream
+q
+20 0 0 20 0 100 cm
+/Im1 Do
+Q
+BT
+/Cs1 cs
+1 0 0 0 scn
+30 20 50 40 re f
+ET
+endstream
+endobj
+5 0 obj <<
+ /ColorSpace <<
+ /Cs1 /DeviceCMYK
+ >>
+ /ProcSet [/PDF /ImageB]
+ /XObject <<
+ /Im1 6 0 R
+ >>
+>>
+endobj
+6 0 obj <<
+ /Type /XObject
+ /Subtype /Image
+ /Width 1
+ /Height 1
+ /BitsPerComponent 8
+ /ColorSpace /DeviceGray
+ /Filter /ASCIIHexDecode
+ /Length 3
+>>
+stream
+33
+endstream
+endobj
+xref
+0 7
+0000000000 65535 f
+0000000015 00000 n
+0000000068 00000 n
+0000000131 00000 n
+0000000245 00000 n
+0000000370 00000 n
+0000000494 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 7
+>>
+startxref
+679
+%%EOF