Add an embedded test case
authorJun Fang <jun_fang@foxitsoftware.com>
Mon, 26 Oct 2015 13:07:08 +0000 (21:07 +0800)
committerJun Fang <jun_fang@foxitsoftware.com>
Tue, 27 Oct 2015 03:27:29 +0000 (11:27 +0800)
BUILD.gn
pdfium.gyp
testing/resources/bug_216.pdf [new file with mode: 0644]
xfa/src/fxfa/src/parser/xfa_parser_imp.cpp
xfa/src/fxfa/src/parser/xfa_parser_imp_embeddertest.cpp [new file with mode: 0644]

index 5657296..8f8b903 100644 (file)
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1511,6 +1511,7 @@ test("pdfium_embeddertests") {
     "testing/embedder_test.h",
     "testing/embedder_test_mock_delegate.h",
     "testing/embedder_test_timer_handling_delegate.h",
+    "xfa/src/fxfa/src/parser/xfa_parser_imp_embeddertest.cpp",
   ]
   deps = [
     "//testing/gmock",
index b101096..22d6304 100644 (file)
         'testing/embedder_test.h',
         'testing/embedder_test_mock_delegate.h',
         'testing/embedder_test_timer_handling_delegate.h',
+        'xfa/src/fxfa/src/parser/xfa_parser_imp_embeddertest.cpp',
       ],
       'conditions': [
         ['pdf_enable_v8==1', {
diff --git a/testing/resources/bug_216.pdf b/testing/resources/bug_216.pdf
new file mode 100644 (file)
index 0000000..1cb8884
--- /dev/null
@@ -0,0 +1,39 @@
+%PDF-1.7
+1 0 obj <<
+  /Type /Catalog
+  /Pages 2 0 R
+  /AcroForm 4 0 R
+>>
+endobj
+2 0 obj <<
+  /Type /Pages
+  /Count 1
+>>
+endobj
+4 0 obj <<
+  /XFA [
+    (xdp:xdp) 23 0 R
+    (form) 29 0 R
+    (</xdp:xdp>) 30 0 R]
+>>
+endobj
+23 0 obj <<
+>>stream
+<?xml version="1.0" encoding="UTF-8"?>
+<xdp:xdp xmlns:xdp="http://www.foxitsoftware.com/">
+endstream
+endobj
+29 0 obj <<
+>>stream
+<form xmlns="http://www.xfa.org/schema/xfa-form/2.6/">
+</form>
+endstream
+endobj
+30 0 obj <<
+>>stream
+</xdp:xdp>
+endstream
+endobj
+trailer
+<</Root 1 0 R>>
+%%EOF
index 9e85c1f..6625898 100644 (file)
@@ -433,6 +433,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP(
   }\r
   IFDE_XMLNode* pXMLDatasetsDOMRoot = NULL;\r
   IFDE_XMLNode* pXMLFormDOMRoot = NULL;\r
+  IFDE_XMLNode* pXMLTemplateDOMRoot = NULL;\r
   {\r
     for (IFDE_XMLNode* pChildItem =\r
              pXMLDocumentNode->GetNodeItem(IFDE_XMLNode::FirstChild);\r
@@ -473,7 +474,17 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP(
           return NULL;\r
         }\r
         pXMLFormDOMRoot = pElement;\r
-      } else {\r
+      } else if (ePacket == XFA_XDPPACKET_Template) {\r
+        if (pXMLTemplateDOMRoot) {\r
+          // Find a duplicate template packet\r
+          return NULL;\r
+        }\r
+        CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket);\r
+        if (pPacketNode) {\r
+          pXMLTemplateDOMRoot = pElement;\r
+          pXFARootNode->InsertChild(pPacketNode);\r
+        }\r
+         } else {\r
         CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket);\r
         if (pPacketNode) {\r
           if (pPacketInfo &&\r
@@ -486,6 +497,9 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP(
       }\r
     }\r
   }\r
+  if (!pXMLTemplateDOMRoot) {\r
+    return NULL;\r
+  }\r
   if (pXMLDatasetsDOMRoot) {\r
     CXFA_Node* pPacketNode =\r
         ParseAsXDPPacket(pXMLDatasetsDOMRoot, XFA_XDPPACKET_Datasets);\r
diff --git a/xfa/src/fxfa/src/parser/xfa_parser_imp_embeddertest.cpp b/xfa/src/fxfa/src/parser/xfa_parser_imp_embeddertest.cpp
new file mode 100644 (file)
index 0000000..8bff2f6
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "../../../../../testing/embedder_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class XFAParserImpEmbeddertest : public EmbedderTest {};
+
+TEST_F(XFAParserImpEmbeddertest, Bug_216) {
+       EXPECT_TRUE(OpenDocument("testing/resources/bug_216.pdf"));
+       FPDF_PAGE page = LoadPage(0);
+       EXPECT_NE(nullptr, page);
+       UnloadPage(page);
+}
\ No newline at end of file