Revert "Provide correct state to pattern rendering."
This reverts commit f188aca283d6dceb874bbe5e20d8003e6bbe184f.
Reason for revert: Has memory safety issues.
Original change's description:
> Provide correct state to pattern rendering.
>
> According to 8.7.3.1 in the PDF 2.0 spec, a tiling pattern should
> install the graphics state that was in effect at the beginning of the
> pattern’s parent content stream.
>
> This means that when loading the pattern we have to supply the current
> graphics state and we also can’t keep the pattern loaded past the
> current usage.
>
> Bug: pdfium:1286
> Change-Id: Id9f609a52803fec29cb42be2ef9bcda6ff31ce3c
> Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/53330
> Reviewed-by: Lei Zhang <thestig@chromium.org>
> Commit-Queue: Lei Zhang <thestig@chromium.org>
TBR=thestig@chromium.org,patrik@pspdfkit.com
Change-Id: I89d16a263a53e0298fe5cf812f16da14d6bbbf2d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: pdfium:1286,chromium:957814
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/53711
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_tilingpattern.cpp b/core/fpdfapi/page/cpdf_tilingpattern.cpp
index e414390..faa7eb8 100644
--- a/core/fpdfapi/page/cpdf_tilingpattern.cpp
+++ b/core/fpdfapi/page/cpdf_tilingpattern.cpp
@@ -6,9 +6,7 @@
#include "core/fpdfapi/page/cpdf_tilingpattern.h"
-#include "core/fpdfapi/page/cpdf_allstates.h"
#include "core/fpdfapi/page/cpdf_form.h"
-#include "core/fpdfapi/page/cpdf_pageobject.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_object.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
@@ -33,7 +31,7 @@
return nullptr;
}
-bool CPDF_TilingPattern::Load(CPDF_PageObject* pPageObj) {
+bool CPDF_TilingPattern::Load() {
if (m_pForm)
return true;
@@ -51,26 +49,7 @@
const CFX_Matrix& matrix = parent_matrix();
m_pForm = pdfium::MakeUnique<CPDF_Form>(document(), nullptr, pStream);
-
- CPDF_AllStates allStates;
- allStates.CopyStates(*pPageObj);
- // Reset color state to default. The current pattern is set in the color
- // state and this would lead to recursion problems. We also reset the
- // clip path as it isn't relevant for pattern rendering either.
- allStates.m_ColorState.SetDefault();
- allStates.m_ClipPath.SetNull();
- m_pForm->ParseContent(&allStates, &matrix, nullptr, nullptr);
+ m_pForm->ParseContent(nullptr, &matrix, nullptr, nullptr);
m_BBox = pDict->GetRectFor("BBox");
return true;
}
-
-void CPDF_TilingPattern::Unload() {
- m_pForm.reset();
-}
-
-CPDF_TilingPattern::Unloader::Unloader(CPDF_TilingPattern* pattern)
- : m_pTilingPattern(pattern) {}
-
-CPDF_TilingPattern::Unloader::~Unloader() {
- m_pTilingPattern->Unload();
-}
diff --git a/core/fpdfapi/page/cpdf_tilingpattern.h b/core/fpdfapi/page/cpdf_tilingpattern.h
index 3cca606..c79708d 100644
--- a/core/fpdfapi/page/cpdf_tilingpattern.h
+++ b/core/fpdfapi/page/cpdf_tilingpattern.h
@@ -16,19 +16,9 @@
class CPDF_Document;
class CPDF_Form;
class CPDF_Object;
-class CPDF_PageObject;
class CPDF_TilingPattern final : public CPDF_Pattern {
public:
- class Unloader {
- public:
- explicit Unloader(CPDF_TilingPattern* pTilingPattern);
- ~Unloader();
-
- private:
- UnownedPtr<CPDF_TilingPattern> const m_pTilingPattern;
- };
-
CPDF_TilingPattern(CPDF_Document* pDoc,
CPDF_Object* pPatternObj,
const CFX_Matrix& parentMatrix);
@@ -37,8 +27,7 @@
CPDF_TilingPattern* AsTilingPattern() override;
CPDF_ShadingPattern* AsShadingPattern() override;
- bool Load(CPDF_PageObject* pPageObj);
- void Unload();
+ bool Load();
bool colored() const { return m_bColored; }
const CFX_FloatRect& bbox() const { return m_BBox; }
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index e816480..8f7dd84 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -2143,8 +2143,7 @@
CPDF_PageObject* pPageObj,
const CFX_Matrix& mtObj2Device,
bool bStroke) {
- CPDF_TilingPattern::Unloader unloader(pPattern);
- if (!pPattern->Load(pPageObj))
+ if (!pPattern->Load())
return;
CFX_RenderDevice::StateRestorer restorer(m_pDevice);
diff --git a/testing/resources/pixel/bug_1161_expected.pdf.0.png b/testing/resources/pixel/bug_1161_expected.pdf.0.png
index 745b8c3..f54d0ec 100644
--- a/testing/resources/pixel/bug_1161_expected.pdf.0.png
+++ b/testing/resources/pixel/bug_1161_expected.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/bug_1286.in b/testing/resources/pixel/bug_1286.in
deleted file mode 100644
index e3d0133..0000000
--- a/testing/resources/pixel/bug_1286.in
+++ /dev/null
@@ -1,73 +0,0 @@
-{{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
- /Contents 5 0 R
- /MediaBox [0 0 600 850]
- /Parent 3 0 R
- /Resources <<
- /ColorSpace << /CS0 [/Pattern] >>
- /ExtGState << /GS0 6 0 R /GS1 7 0 R >>
- /Pattern << /P0 4 0 R >>
- /ProcSet [/PDF /Text]
- >>
->>
-endobj
-{{object 4 0}} <<
- /Type /Pattern
- /BBox [0 0 72 72]
- /PaintType 1
- /PatternType 1
- /Resources << /ExtGState << /GS0 7 0 R >> >>
- /TilingType 1
- /XStep 72
- /YStep 72
- {{streamlen}}
->>
-stream
-0 0 72 72 re B
-endstream
-endobj
-{{object 5 0}} <<
- {{streamlen}}
->>
-stream
-q
-/GS0 gs /Pattern cs /P0 scn
-50 700 100 100 re
-B
-Q
-
-q
-/GS1 gs /Pattern cs /P0 scn
-50 580 100 100 re
-B
-Q
-endstream
-endobj
-{{object 6 0}} <<
- /Type /ExtGState
- /CA 0.199997
- /ca 0.199997
->>
-endobj
-{{object 7 0}} <<
- /Type /ExtGState
- /CA 1
- /ca 1
->>
-endobj
-{{xref}}
-{{trailer}}
-{{startxref}}
-%%EOF
diff --git a/testing/resources/pixel/bug_1286_expected.pdf.0.png b/testing/resources/pixel/bug_1286_expected.pdf.0.png
deleted file mode 100644
index de21a23..0000000
--- a/testing/resources/pixel/bug_1286_expected.pdf.0.png
+++ /dev/null
Binary files differ