diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-18 16:58:07 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-18 16:58:07 +0000 |
commit | 4df46054105e71ecc6a80d29c8d56ef0778b5aa8 (patch) | |
tree | 4510d8739ee65cdb56aacbd640d22222f89bc41f /xfa/fgas/font/cfgas_fontmgr.cpp | |
parent | 95d525e83f1f5b5fac15970f767410b21debbb81 (diff) | |
download | pdfium-4df46054105e71ecc6a80d29c8d56ef0778b5aa8.tar.xz |
Cache CFGAS_FontMgr::GetFontByUnicode() failures on Windows.
Non-Windows does this already, which is why it can handle fuzzers that
throws the same invalid unicode character at it efficiently. Whereas
Windows tries to do the same failing font load repeatedly.
BUG=chromium:895469
Change-Id: I6780d1ec0881222348e05a5a63e7b2238f39a3a6
Reviewed-on: https://pdfium-review.googlesource.com/c/44251
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fgas/font/cfgas_fontmgr.cpp')
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.cpp | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 8881be74f6..22e97f076c 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -27,6 +27,23 @@ #include "xfa/fgas/font/cfx_fontsourceenum_file.h" #endif +namespace { + +bool VerifyUnicode(const RetainPtr<CFGAS_GEFont>& pFont, wchar_t wcUnicode) { + FXFT_Face pFace = pFont->GetDevFont()->GetFace(); + FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); + if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0) + return false; + + if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) { + FXFT_Set_Charmap(pFace, charmap); + return false; + } + return true; +} + +} // namespace + #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ namespace { @@ -182,6 +199,11 @@ RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicodeImpl( return nullptr; pFont->SetLogicalFontStyle(dwFontStyles); + if (!VerifyUnicode(pFont, wUnicode)) { + m_FailedUnicodesSet.insert(wUnicode); + return nullptr; + } + m_Hash2Fonts[dwHash].push_back(pFont); return pFont; } @@ -779,26 +801,6 @@ void CFGAS_FontMgr::RegisterFaces( #endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ -namespace { - -bool VerifyUnicode(const RetainPtr<CFGAS_GEFont>& pFont, wchar_t wcUnicode) { - if (!pFont) - return false; - - FXFT_Face pFace = pFont->GetDevFont()->GetFace(); - FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); - if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0) - return false; - - if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) { - FXFT_Set_Charmap(pFace, charmap); - return false; - } - return true; -} - -} // namespace - RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByCodePage( uint16_t wCodePage, uint32_t dwFontStyles, @@ -857,10 +859,8 @@ RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicode( wchar_t wUnicode, uint32_t dwFontStyles, const wchar_t* pszFontFamily) { -#if _FX_PLATFORM_ != _FX_PLATFORM_WINDOWS_ if (pdfium::ContainsKey(m_FailedUnicodesSet, wUnicode)) return nullptr; -#endif // _FX_PLATFORM_ != _FX_PLATFORM_WINDOWS_ const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; |