Get Attribute names much more simply.

We can now directly index them.

Also avoid unexpected user input aliasing while we're at it by
comparing the name string itself in XFA_GetAttributeByName since
we now have the string in the table.

Change-Id: Ib3ee01197b37d900f96f9665711eeffbd5006565
Reviewed-on: https://pdfium-review.googlesource.com/c/47011
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/parser/xfa_basic_data.cpp b/xfa/fxfa/parser/xfa_basic_data.cpp
index 758c33d..b6fdfc9 100644
--- a/xfa/fxfa/parser/xfa_basic_data.cpp
+++ b/xfa/fxfa/parser/xfa_basic_data.cpp
@@ -169,29 +169,16 @@
 struct AttributeRecord {
   uint32_t hash;  // Hashed as wide string.
   XFA_Attribute attribute;
+  const char* name;
 };
 
 const AttributeRecord g_AttributeTable[] = {
 #undef ATTR____
-#define ATTR____(a, b, c) {a, XFA_Attribute::c},
+#define ATTR____(a, b, c) {a, XFA_Attribute::c, b},
 #include "xfa/fxfa/parser/attributes.inc"
 #undef ATTR____
 };
 
-const char* AttributeToNameASCII(XFA_Attribute attr) {
-  switch (attr) {
-#undef ATTR____
-#define ATTR____(a, b, c) \
-  case XFA_Attribute::c:  \
-    return b;
-#include "xfa/fxfa/parser/attributes.inc"
-#undef ATTR____
-    default:
-      NOTREACHED();
-      return "";
-  }
-}
-
 struct AttributeValueRecord {
   uint32_t uHash;  // |pName| hashed as WideString.
   XFA_AttributeValue eName;
@@ -6604,7 +6591,8 @@
 }
 
 WideString XFA_AttributeToName(XFA_Attribute attr) {
-  return WideString::FromASCII(AttributeToNameASCII(attr));
+  return WideString::FromASCII(
+      g_AttributeTable[static_cast<size_t>(attr)].name);
 }
 
 XFA_Attribute XFA_GetAttributeByName(const WideStringView& name) {
@@ -6612,7 +6600,7 @@
   auto* elem = std::lower_bound(
       std::begin(g_AttributeTable), std::end(g_AttributeTable), hash,
       [](const AttributeRecord& a, uint32_t hash) { return a.hash < hash; });
-  if (elem != std::end(g_AttributeTable) && elem->hash == hash)
+  if (elem != std::end(g_AttributeTable) && name.EqualsASCII(elem->name))
     return elem->attribute;
   return XFA_Attribute::Unknown;
 }