summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2016-02-22 20:47:13 -0800
committerLei Zhang <thestig@chromium.org>2016-02-22 20:47:13 -0800
commit7f9fddeaaaddb5a898f1431e7d2d8b89d40fad87 (patch)
tree3246a58132c45a9e0487fa8a3319c5ab755ff4b5 /fpdfsdk/src
parent5eca305b1586b2107566a5c124baa5f2e00096c0 (diff)
downloadpdfium-7f9fddeaaaddb5a898f1431e7d2d8b89d40fad87.tar.xz
FPDFPage_HasFormFieldAtPoint should not crash for nullptr pages.
BUG=pdfium:401 R=jun_fang@foxitsoftware.com Review URL: https://codereview.chromium.org/1713833003 .
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/fpdfformfill.cpp95
1 files changed, 41 insertions, 54 deletions
diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp
index e39d623307..c1f332bd74 100644
--- a/fpdfsdk/src/fpdfformfill.cpp
+++ b/fpdfsdk/src/fpdfformfill.cpp
@@ -56,73 +56,60 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
if (!hHandle)
return -1;
CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
-#ifdef PDF_ENABLE_XFA
if (pPage) {
CPDF_InterForm interform(pPage->m_pDocument, FALSE);
- CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
- pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr);
+ CPDF_FormControl* pFormCtrl =
+ interform.GetControlAtPoint(pPage, static_cast<FX_FLOAT>(page_x),
+ static_cast<FX_FLOAT>(page_y), nullptr);
if (!pFormCtrl)
return -1;
-
CPDF_FormField* pFormField = pFormCtrl->GetField();
- if (!pFormField)
- return -1;
-
- int nType = pFormField->GetFieldType();
- return nType;
+ return pFormField ? pFormField->GetFieldType() : -1;
}
- IXFA_PageView* pPageView = ((CPDFXFA_Page*)page)->GetXFAPageView();
- if (pPageView) {
- IXFA_WidgetHandler* pWidgetHandler = NULL;
- IXFA_DocView* pDocView = pPageView->GetDocView();
- if (!pDocView)
- return -1;
+#ifdef PDF_ENABLE_XFA
+ CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page);
+ if (!pXFAPage)
+ return -1;
- pWidgetHandler = pDocView->GetWidgetHandler();
- if (!pWidgetHandler)
- return -1;
+ IXFA_PageView* pPageView = pXFAPage->GetXFAPageView();
+ if (!pPageView)
+ return -1;
- IXFA_Widget* pXFAAnnot = NULL;
- IXFA_WidgetIterator* pWidgetIterator = pPageView->CreateWidgetIterator(
- XFA_TRAVERSEWAY_Form,
- XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_AllType);
- if (!pWidgetIterator)
- return -1;
- pXFAAnnot = pWidgetIterator->MoveToNext();
- while (pXFAAnnot) {
- CFX_RectF rcBBox;
- pWidgetHandler->GetBBox(pXFAAnnot, rcBBox, 0);
- CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top,
- rcBBox.left + rcBBox.width,
- rcBBox.top + rcBBox.height);
- rcWidget.left -= 1.0f;
- rcWidget.right += 1.0f;
- rcWidget.bottom -= 1.0f;
- rcWidget.top += 1.0f;
-
- if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x),
- static_cast<FX_FLOAT>(page_y))) {
- pWidgetIterator->Release();
- return FPDF_FORMFIELD_XFA;
- }
- pXFAAnnot = pWidgetIterator->MoveToNext();
- }
+ IXFA_DocView* pDocView = pPageView->GetDocView();
+ if (!pDocView)
+ return -1;
- pWidgetIterator->Release();
- }
- return -1;
-#else // PDF_ENABLE_XFA
- if (!pPage)
+ IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
+ if (!pWidgetHandler)
return -1;
- CPDF_InterForm interform(pPage->m_pDocument, FALSE);
- CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
- pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr);
- if (!pFormCtrl)
+
+ std::unique_ptr<IXFA_WidgetIterator, ReleaseDeleter<IXFA_WidgetIterator>>
+ pWidgetIterator(pPageView->CreateWidgetIterator(
+ XFA_TRAVERSEWAY_Form,
+ XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_AllType));
+ if (!pWidgetIterator)
return -1;
- CPDF_FormField* pFormField = pFormCtrl->GetField();
- return pFormField ? pFormField->GetFieldType() : -1;
+
+ IXFA_Widget* pXFAAnnot = pWidgetIterator->MoveToNext();
+ while (pXFAAnnot) {
+ CFX_RectF rcBBox;
+ pWidgetHandler->GetBBox(pXFAAnnot, rcBBox, 0);
+ CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
+ rcBBox.top + rcBBox.height);
+ rcWidget.left -= 1.0f;
+ rcWidget.right += 1.0f;
+ rcWidget.bottom -= 1.0f;
+ rcWidget.top += 1.0f;
+
+ if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x),
+ static_cast<FX_FLOAT>(page_y))) {
+ return FPDF_FORMFIELD_XFA;
+ }
+ pXFAAnnot = pWidgetIterator->MoveToNext();
+ }
#endif // PDF_ENABLE_XFA
+ return -1;
}
DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,