Switch from DataVector to FixedDataVector CPDF_CMap.

Use FixedDataVector since the vector has a fixed size, but does need to
be initialized. Also make the vector size a constant and use it in
CPDF_CMapParser.

Change-Id: Ifee8842bd7813c679cc881a2e1b73cbed77d1dd9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/98172
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cmap.cpp b/core/fpdfapi/font/cpdf_cmap.cpp
index 8e93bae..e71f956 100644
--- a/core/fpdfapi/font/cpdf_cmap.cpp
+++ b/core/fpdfapi/font/cpdf_cmap.cpp
@@ -318,7 +318,7 @@
 }
 
 CPDF_CMap::CPDF_CMap(pdfium::span<const uint8_t> spEmbeddedData)
-    : m_DirectCharcodeToCIDTable(65536) {
+    : m_DirectCharcodeToCIDTable(kDirectMapTableSize) {
   CPDF_CMapParser parser(this);
   CPDF_SimpleParser syntax(spEmbeddedData);
   while (true) {
@@ -342,8 +342,9 @@
   if (m_DirectCharcodeToCIDTable.empty())
     return static_cast<uint16_t>(charcode);
 
-  if (charcode < 0x10000)
-    return m_DirectCharcodeToCIDTable[charcode];
+  auto table_span = m_DirectCharcodeToCIDTable.span();
+  if (charcode < table_span.size())
+    return table_span[charcode];
 
   auto it = std::lower_bound(m_AdditionalCharcodeToCIDMappings.begin(),
                              m_AdditionalCharcodeToCIDMappings.end(), charcode,
diff --git a/core/fpdfapi/font/cpdf_cmap.h b/core/fpdfapi/font/cpdf_cmap.h
index 5ce9496..b7fa49b 100644
--- a/core/fpdfapi/font/cpdf_cmap.h
+++ b/core/fpdfapi/font/cpdf_cmap.h
@@ -12,7 +12,7 @@
 #include <vector>
 
 #include "core/fpdfapi/font/cpdf_cidfont.h"
-#include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/fixed_zeroed_data_vector.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxcrt/unowned_ptr.h"
 #include "third_party/base/span.h"
@@ -32,6 +32,8 @@
 
 class CPDF_CMap final : public Retainable {
  public:
+  static constexpr size_t kDirectMapTableSize = 65536;
+
   enum CodingScheme : uint8_t {
     OneByte,
     TwoBytes,
@@ -74,7 +76,7 @@
   void SetCharset(CIDSet set) { m_Charset = set; }
 
   void SetDirectCharcodeToCIDTable(size_t idx, uint16_t val) {
-    m_DirectCharcodeToCIDTable[idx] = val;
+    m_DirectCharcodeToCIDTable.writable_span()[idx] = val;
   }
   bool IsDirectCharcodeToCIDTableIsEmpty() const {
     return m_DirectCharcodeToCIDTable.empty();
@@ -92,7 +94,7 @@
   CIDCoding m_Coding = CIDCoding::kUNKNOWN;
   std::vector<bool> m_MixedTwoByteLeadingBytes;
   std::vector<CodeRange> m_MixedFourByteLeadingRanges;
-  DataVector<uint16_t> m_DirectCharcodeToCIDTable;
+  FixedZeroedDataVector<uint16_t> m_DirectCharcodeToCIDTable;
   std::vector<CIDRange> m_AdditionalCharcodeToCIDMappings;
   UnownedPtr<const FXCMAP_CMap> m_pEmbedMap;
 };
diff --git a/core/fpdfapi/font/cpdf_cmapparser.cpp b/core/fpdfapi/font/cpdf_cmapparser.cpp
index 98bcad3..bfe3f79 100644
--- a/core/fpdfapi/font/cpdf_cmapparser.cpp
+++ b/core/fpdfapi/font/cpdf_cmapparser.cpp
@@ -99,7 +99,7 @@
     EndCode = m_CodePoints[1];
     StartCID = static_cast<uint16_t>(m_CodePoints[2]);
   }
-  if (EndCode < 0x10000) {
+  if (EndCode < CPDF_CMap::kDirectMapTableSize) {
     for (uint32_t code = StartCode; code <= EndCode; code++) {
       m_pCMap->SetDirectCharcodeToCIDTable(
           code, static_cast<uint16_t>(StartCID + code - StartCode));