M96: Remove CPDF_Dictionary::IsValidKey().

- The project leader for ISO 32000 says it is wrong.
- https://crbug.com/1248924#c8 contains a PDF with non-ASCII keys that
  work in other PDF viewers.

Bug: pdfium:1729,chromium:1261493
Change-Id: Ica23e5fe655696bed5df0126b350cc6110ce25f5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86131
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
(cherry picked from commit aa648bc5f4ee2ee181136a8262c56cf91cd9785b)
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86291
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 112d457..6a8ed3e 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -618,13 +618,11 @@
     auto word = m_pSyntax->GetWord();
     ByteString key(word.Last(word.GetLength() - 1));
     auto pObj = m_pSyntax->ReadNextObject(false, false, 0);
-    if (CPDF_Dictionary::IsValidKey(key)) {
-      if (pObj && !pObj->IsInline()) {
-        pDict->SetNewFor<CPDF_Reference>(key, m_pDocument.Get(),
-                                         pObj->GetObjNum());
-      } else {
-        pDict->SetFor(key, std::move(pObj));
-      }
+    if (pObj && !pObj->IsInline()) {
+      pDict->SetNewFor<CPDF_Reference>(key, m_pDocument.Get(),
+                                       pObj->GetObjNum());
+    } else {
+      pDict->SetFor(key, std::move(pObj));
     }
   }
   ReplaceAbbr(pDict.Get());
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index 31c59c5..1c1e4fd 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -345,8 +345,7 @@
       if (!pObj)
         return nullptr;
 
-      if (CPDF_Dictionary::IsValidKey(key))
-        pDict->SetFor(key, std::move(pObj));
+      pDict->SetFor(key, std::move(pObj));
     }
     return pDict;
   }
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp
index 0494372..a798b6e 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/parser/cpdf_dictionary.cpp
@@ -82,11 +82,6 @@
   return pCopy;
 }
 
-// static
-bool CPDF_Dictionary::IsValidKey(const ByteString& key) {
-  return !key.IsEmpty() && key.AsStringView().IsASCII();
-}
-
 const CPDF_Object* CPDF_Dictionary::GetObjectFor(const ByteString& key) const {
   auto it = m_Map.find(key);
   return it != m_Map.end() ? it->second.Get() : nullptr;
@@ -215,7 +210,6 @@
 
 CPDF_Object* CPDF_Dictionary::SetFor(const ByteString& key,
                                      RetainPtr<CPDF_Object> pObj) {
-  CHECK(IsValidKey(key));
   CHECK(!IsLocked());
   if (!pObj) {
     m_Map.erase(key);
diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h
index 83c099e..a7d303f 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.h
+++ b/core/fpdfapi/parser/cpdf_dictionary.h
@@ -40,9 +40,6 @@
   bool WriteTo(IFX_ArchiveStream* archive,
                const CPDF_Encryptor* encryptor) const override;
 
-  // `key` must be non-empty and ASCII, per PDF 32000 standard, section 7.2.1.
-  static bool IsValidKey(const ByteString& key);
-
   bool IsLocked() const { return !!m_LockCount; }
 
   size_t size() const { return m_Map.size(); }
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 601d2ad..d71d233 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -594,8 +594,7 @@
       // `key` has to be "/X" at the minimum.
       if (key.GetLength() > 1) {
         ByteString key_no_slash(key.raw_str() + 1, key.GetLength() - 1);
-        if (CPDF_Dictionary::IsValidKey(key_no_slash))
-          pDict->SetFor(key_no_slash, std::move(pObj));
+        pDict->SetFor(key_no_slash, std::move(pObj));
       }
     }
 
diff --git a/core/fpdfdoc/cpdf_generateap.cpp b/core/fpdfdoc/cpdf_generateap.cpp
index 5ab2e0f..10602cf 100644
--- a/core/fpdfdoc/cpdf_generateap.cpp
+++ b/core/fpdfdoc/cpdf_generateap.cpp
@@ -942,8 +942,6 @@
     return;
 
   ByteString font_name = font.value();
-  if (!CPDF_Dictionary::IsValidKey(font_name))
-    return;
 
   CFX_Color crText = fpdfdoc::CFXColorFromString(DA);
   CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR");
diff --git a/fpdfsdk/cpdfsdk_appstream.cpp b/fpdfsdk/cpdfsdk_appstream.cpp
index c3fd4fb..0a7c966 100644
--- a/fpdfsdk/cpdfsdk_appstream.cpp
+++ b/fpdfsdk/cpdfsdk_appstream.cpp
@@ -1830,11 +1830,8 @@
   ByteString sImageAlias = "IMG";
 
   CPDF_Dictionary* pImageDict = pImage->GetDict();
-  if (pImageDict) {
-    ByteString image_name = pImageDict->GetStringFor("Name");
-    if (CPDF_Dictionary::IsValidKey(image_name))
-      sImageAlias = std::move(image_name);
-  }
+  if (pImageDict)
+    sImageAlias = pImageDict->GetStringFor("Name");
 
   CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
   if (!pStreamResList)
diff --git a/testing/resources/bad_dict_keys.in b/testing/resources/bad_dict_keys.in
index 9eb648b..3f53c28 100644
--- a/testing/resources/bad_dict_keys.in
+++ b/testing/resources/bad_dict_keys.in
@@ -10,7 +10,6 @@
   /Count 1
   /Kids [3 0 R]
   / [3 0 R]
-  /#80 [3 0 R]
 >>
 endobj
 {{object 3 0}} <<
diff --git a/testing/resources/bad_dict_keys.pdf b/testing/resources/bad_dict_keys.pdf
index 9ab931c..b55c434 100644
--- a/testing/resources/bad_dict_keys.pdf
+++ b/testing/resources/bad_dict_keys.pdf
@@ -11,7 +11,6 @@
   /Count 1
   /Kids [3 0 R]
   / [3 0 R]
-  /#80 [3 0 R]
 >>
 endobj
 3 0 obj <<
@@ -24,11 +23,11 @@
 0000000000 65535 f 
 0000000015 00000 n 
 0000000068 00000 n 
-0000000184 00000 n 
+0000000169 00000 n 
 trailer <<
   /Root 1 0 R
   /Size 4
 >>
 startxref
-235
+220
 %%EOF