Handle removed fonts correctly in GetFontByCodePage

The existing code has a couple of issues that need to be
addressed. First it assumes that for a hash, there will be an entry in
the map and blindly calls the [] operator and takes the address of the
result. If there isn't an entry for the hash then this will cause a
crash. This has been converted to a call to find and returning
nullptr, which is the fail result, if it cannot find an entry for the
hash.

The other issue is that it assumed that the first entry in the vector
would be a valid pointer. When removing fonts from the vector,
RemoveFont, first nulls out entries. Once all of the entries have been
removed from a vector on subsequent calls to RemoveFont, then the
vector is removed from the map. Thus the first entry in the vector
might not be the correct value to return. This has been changed to a
linear scan of the vector for a valid pointer.

BUG=chromium:648177

Change-Id: Ife758636545f0d10fb726c243e3e0a5b7c1d1138
Reviewed-on: https://pdfium-review.googlesource.com/25930
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 1731079..99120a0 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -951,9 +951,14 @@
   ByteString bsHash = ByteString::Format("%d, %d", wCodePage, dwFontStyles);
   bsHash += FX_UTF8Encode(WideStringView(pszFontFamily));
   uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringView(), false);
-  std::vector<RetainPtr<CFGAS_GEFont>>* pFontArray = &m_Hash2Fonts[dwHash];
-  if (!pFontArray->empty())
-    return (*pFontArray)[0];
+  auto* pFontVector = &m_Hash2Fonts[dwHash];
+  if (!pFontVector->empty()) {
+    for (auto iter = pFontVector->begin(); iter != pFontVector->end(); ++iter) {
+      if (*iter != nullptr)
+        return *iter;
+    }
+    return nullptr;
+  }
 
 #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
   const FX_FONTDESCRIPTOR* pFD =
@@ -989,7 +994,7 @@
     return nullptr;
 
   pFont->SetLogicalFontStyle(dwFontStyles);
-  pFontArray->push_back(pFont);
+  pFontVector->push_back(pFont);
   return pFont;
 }