summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-02-07 21:01:44 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-07 21:01:44 +0000
commit161f992a81e400eeebba49387f174d836750d624 (patch)
tree507d18b7b34344a7b98756318d0cdac0b752fd33
parenta98e36657d0e5a78e216f828b3e712e85250c1a7 (diff)
downloadpdfium-161f992a81e400eeebba49387f174d836750d624.tar.xz
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>
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 1731079bdd..99120a0d51 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -951,9 +951,14 @@ RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByCodePage(
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 @@ RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByCodePage(
return nullptr;
pFont->SetLogicalFontStyle(dwFontStyles);
- pFontArray->push_back(pFont);
+ pFontVector->push_back(pFont);
return pFont;
}