Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp

Issue 1539193003: Fix crashing in CPDFXFA_Document::GetPage() (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fpdfsdk/include/fsdk_mgr.h ('k') | fpdfsdk/src/fsdk_mgr.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp
diff --git a/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp
index 92d16b64e233dcc15cbaac64c5abe5cb2c31a965..e72c1b3f16410d2e69e5129cbb94885b11078be9 100644
--- a/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp
+++ b/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp
@@ -138,29 +138,25 @@ int CPDFXFA_Document::GetPageCount() {
}
CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) {
- if (!m_pPDFDoc && !m_pXFADoc)
- return NULL;
-
- CPDFXFA_Page* pPage = NULL;
- if (m_XFAPageList.GetSize()) {
+ if (page_index < 0)
+ return nullptr;
+ CPDFXFA_Page* pPage = nullptr;
+ int nCount = m_XFAPageList.GetSize();
+ if (nCount > 0 && page_index < nCount) {
pPage = m_XFAPageList.GetAt(page_index);
if (pPage)
pPage->AddRef();
} else {
m_XFAPageList.SetSize(GetPageCount());
}
-
- if (!pPage) {
- pPage = new CPDFXFA_Page(this, page_index);
- FX_BOOL bRet = pPage->LoadPage();
- if (!bRet) {
- delete pPage;
- return NULL;
- }
-
- m_XFAPageList.SetAt(page_index, pPage);
+ if (pPage)
+ return pPage;
+ pPage = new CPDFXFA_Page(this, page_index);
+ if (!pPage->LoadPage()) {
+ delete pPage;
+ return nullptr;
}
-
+ m_XFAPageList.SetAt(page_index, pPage);
return pPage;
}
@@ -476,6 +472,22 @@ FX_BOOL CPDFXFA_Document::PopupMenu(IXFA_Widget* hWidget,
void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView,
FX_DWORD dwFlags) {
+ if (!pPageView || (dwFlags != XFA_PAGEVIEWEVENT_PostAdded &&
+ dwFlags != XFA_PAGEVIEWEVENT_PostRemoved)) {
+ return;
+ }
+ CPDFXFA_Page* pPage = nullptr;
+ if (dwFlags == XFA_PAGEVIEWEVENT_PostAdded) {
+ pPage = GetPage(pPageView->GetPageViewIndex());
+ if (pPage)
+ pPage->SetXFAPageView(pPageView);
+ return;
+ }
+ pPage = GetPage(pPageView);
+ if (!pPage)
+ return;
+ pPage->SetXFAPageView(nullptr);
+ m_pSDKDoc->GetPageView(pPage)->ClearFXAnnots();
}
void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget,
« no previous file with comments | « fpdfsdk/include/fsdk_mgr.h ('k') | fpdfsdk/src/fsdk_mgr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698