From eb3ec8f29846a5df67269a53ca94d1d740c84513 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 25 Apr 2018 18:49:21 +0000 Subject: Allow failing to build CFXA_FWLTheme if unable to load fonts The current implementation of this class potentially does a lot of work in the constructor. Specifically when getting a calendar font it might cause the whole font loading pipeline to run. This can fail if it is unable to load fonts. Breaking out the font loading part, so that the factory method can return nullptr if it fails. Additionally adding a guard for the case the font manager fails to load, which is the root cause of the crash in the bug. BUG=chromium:835608 Change-Id: I05b987aaad6f0814907066904331610a7fbb7f70 Reviewed-on: https://pdfium-review.googlesource.com/31330 Commit-Queue: Ryan Harrison Reviewed-by: Henrique Nakashima --- xfa/fxfa/cxfa_ffapp.cpp | 5 ++++- xfa/fxfa/cxfa_fwltheme.cpp | 12 +++++++++--- xfa/fxfa/cxfa_fwltheme.h | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'xfa') diff --git a/xfa/fxfa/cxfa_ffapp.cpp b/xfa/fxfa/cxfa_ffapp.cpp index 777e2a4241..67a7270824 100644 --- a/xfa/fxfa/cxfa_ffapp.cpp +++ b/xfa/fxfa/cxfa_ffapp.cpp @@ -52,8 +52,11 @@ CFGAS_FontMgr* CXFA_FFApp::GetFDEFontMgr() { } CXFA_FWLTheme* CXFA_FFApp::GetFWLTheme() { - if (!m_pFWLTheme) + if (!m_pFWLTheme) { m_pFWLTheme = pdfium::MakeUnique(this); + if (!m_pFWLTheme->LoadCalendarFont()) + m_pFWLTheme = nullptr; + } return m_pFWLTheme.get(); } diff --git a/xfa/fxfa/cxfa_fwltheme.cpp b/xfa/fxfa/cxfa_fwltheme.cpp index 0f41052d3b..22e091ee12 100644 --- a/xfa/fxfa/cxfa_fwltheme.cpp +++ b/xfa/fxfa/cxfa_fwltheme.cpp @@ -60,18 +60,24 @@ CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp) m_pCalendarFont(nullptr), m_pApp(pApp) { m_Rect.Reset(); +} +bool CXFA_FWLTheme::LoadCalendarFont() { for (size_t i = 0; !m_pCalendarFont && i < FX_ArraySize(g_FWLTheme_CalFonts); ++i) { m_pCalendarFont = CFGAS_GEFont::LoadFont(g_FWLTheme_CalFonts[i], 0, 0, m_pApp->GetFDEFontMgr()); } + if (!m_pCalendarFont) { - m_pCalendarFont = m_pApp->GetFDEFontMgr()->GetFontByCodePage( - FX_CODEPAGE_MSWin_WesternEuropean, 0, nullptr); + CFGAS_FontMgr* font_mgr = m_pApp->GetFDEFontMgr(); + if (font_mgr) { + m_pCalendarFont = font_mgr->GetFontByCodePage( + FX_CODEPAGE_MSWin_WesternEuropean, 0, nullptr); + } } - ASSERT(m_pCalendarFont); + return m_pCalendarFont != nullptr; } CXFA_FWLTheme::~CXFA_FWLTheme() { diff --git a/xfa/fxfa/cxfa_fwltheme.h b/xfa/fxfa/cxfa_fwltheme.h index bdab7cfdc5..b8f8ff68be 100644 --- a/xfa/fxfa/cxfa_fwltheme.h +++ b/xfa/fxfa/cxfa_fwltheme.h @@ -29,6 +29,8 @@ class CXFA_FWLTheme final : public IFWL_ThemeProvider { explicit CXFA_FWLTheme(CXFA_FFApp* pApp); ~CXFA_FWLTheme() override; + bool LoadCalendarFont(); + // IFWL_ThemeProvider: void DrawBackground(CFWL_ThemeBackground* pParams) override; void DrawText(CFWL_ThemeText* pParams) override; -- cgit v1.2.3