Add an element with an invalid /Type to tagged_table_bad_elem.pdf.

Struct elements should either have a proper /Type or no /Type at all.
Modify tagged_table_bad_elem.pdf with more /Type variations in its
struct elements to demonstrate this. Note that Acrobat Reader will show
the bad struct element from this PDF, so no changes are being made to
skip the parsing of that element.

Change-Id: Ib560a6d9376f4226df6ac0813e6a082a0b0fa4b1
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/90571
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_structtree_embeddertest.cpp b/fpdfsdk/fpdf_structtree_embeddertest.cpp
index 280b520..3594f24 100644
--- a/fpdfsdk/fpdf_structtree_embeddertest.cpp
+++ b/fpdfsdk/fpdf_structtree_embeddertest.cpp
@@ -200,6 +200,7 @@
     EXPECT_EQ(18U, FPDF_StructElement_GetType(document, buffer, kBufLen));
     EXPECT_EQ("Document", GetPlatformString(buffer));
 
+    // The table can be retrieved, even though it does not have /Type.
     ASSERT_EQ(1, FPDF_StructElement_CountChildren(document));
     FPDF_STRUCTELEMENT table = FPDF_StructElement_GetChildAtIndex(document, 0);
     ASSERT_TRUE(table);
@@ -210,6 +211,11 @@
     // The table entry cannot be retrieved, as the element is malformed.
     EXPECT_EQ(0U, FPDF_StructElement_GetStringAttribute(table, "Summary",
                                                         buffer, kBufLen));
+
+    // The row can be retrieved, even though it had an invalid /Type.
+    ASSERT_EQ(1, FPDF_StructElement_CountChildren(table));
+    FPDF_STRUCTELEMENT row = FPDF_StructElement_GetChildAtIndex(table, 0);
+    EXPECT_TRUE(row);
   }
 
   UnloadPage(page);
diff --git a/testing/resources/tagged_table_bad_elem.in b/testing/resources/tagged_table_bad_elem.in
index 5fffc93..c502047 100644
--- a/testing/resources/tagged_table_bad_elem.in
+++ b/testing/resources/tagged_table_bad_elem.in
@@ -113,7 +113,7 @@
 {{object 9 0}} <<
   /Nums [
     0
-    [10 0 R 11 0 R]
+    [10 0 R 11 0 R 12 0 R]
   ]
 >>
 endobj
@@ -128,8 +128,9 @@
 >>
 endobj
 {{object 11 0}} <<
-  /Type /StructElem
+  % Deliberately missing /Type
   /S /Table
+  /K [12 0 R]
   /P 10 0 R
   /Pg 3 0 R
   /A [(bogus type)]
@@ -137,6 +138,15 @@
   /Lang (hu)
 >>
 endobj
+{{object 12 0}} <<
+  % Deliberately bad /Type.
+  /Type /NotStructElem
+  /S /TR
+  /P 11 0 R
+  /Pg 3 0 R
+  /ID ()
+>>
+endobj
 {{xref}}
 {{trailer}}
 {{startxref}}
diff --git a/testing/resources/tagged_table_bad_elem.pdf b/testing/resources/tagged_table_bad_elem.pdf
index 82f19e3..62beee0 100644
--- a/testing/resources/tagged_table_bad_elem.pdf
+++ b/testing/resources/tagged_table_bad_elem.pdf
@@ -114,7 +114,7 @@
 9 0 obj <<
   /Nums [
     0
-    [10 0 R 11 0 R]
+    [10 0 R 11 0 R 12 0 R]
   ]
 >>
 endobj
@@ -129,8 +129,9 @@
 >>
 endobj
 11 0 obj <<
-  /Type /StructElem
+  % Deliberately missing /Type
   /S /Table
+  /K [12 0 R]
   /P 10 0 R
   /Pg 3 0 R
   /A [(bogus type)]
@@ -138,8 +139,17 @@
   /Lang (hu)
 >>
 endobj
+12 0 obj <<
+  % Deliberately bad /Type.
+  /Type /NotStructElem
+  /S /TR
+  /P 11 0 R
+  /Pg 3 0 R
+  /ID ()
+>>
+endobj
 xref
-0 12
+0 13
 0000000000 65535 f 
 0000000015 00000 n 
 0000000145 00000 n 
@@ -150,12 +160,13 @@
 0000001212 00000 n 
 0000001253 00000 n 
 0000001412 00000 n 
-0000001473 00000 n 
-0000001600 00000 n 
+0000001480 00000 n 
+0000001607 00000 n 
+0000001758 00000 n 
 trailer <<
   /Root 1 0 R
-  /Size 12
+  /Size 13
 >>
 startxref
-1726
+1873
 %%EOF