Make ReportUnsupportedXFA() more efficient. ReportUnsupportedXFA() instantiates a CPDF_InteractiveForm, which can be expensive, just to read some dictionary values. Replace this with a simple DocHasXFA() function to do just that efficiently. Also remove CPDF_InteractiveForm::HasXFAForm(), which now has no callers. Change-Id: I12cb30edeb4b3ed06896e39486a391f660dcd461 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/67010 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp index a4a1025..8d1267b 100644 --- a/core/fpdfdoc/cpdf_interactiveform.cpp +++ b/core/fpdfdoc/cpdf_interactiveform.cpp
@@ -874,10 +874,6 @@ } } -bool CPDF_InteractiveForm::HasXFAForm() const { - return m_pFormDict && m_pFormDict->GetArrayFor("XFA"); -} - void CPDF_InteractiveForm::FixPageFields(CPDF_Page* pPage) { CPDF_Array* pAnnots = pPage->GetDict()->GetArrayFor("Annots"); if (!pAnnots)
diff --git a/core/fpdfdoc/cpdf_interactiveform.h b/core/fpdfdoc/cpdf_interactiveform.h index 7d1f6c2..eaf7fba 100644 --- a/core/fpdfdoc/cpdf_interactiveform.h +++ b/core/fpdfdoc/cpdf_interactiveform.h
@@ -99,7 +99,6 @@ NotificationOption notify); void SetNotifierIface(NotifierIface* pNotify); - bool HasXFAForm() const; void FixPageFields(CPDF_Page* pPage); NotifierIface* GetFormNotify() const { return m_pFormNotify.Get(); }
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp index 4a1f5b1..f534cf7 100644 --- a/fpdfsdk/cpdfsdk_helpers.cpp +++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -37,6 +37,16 @@ return true; } +// Use the existence of the XFA array as a signal for XFA forms. +bool DocHasXFA(const CPDF_Document* doc) { + const CPDF_Dictionary* root = doc->GetRoot(); + if (!root) + return false; + + const CPDF_Dictionary* form = root->GetDictFor("AcroForm"); + return form && form->GetArrayFor("XFA"); +} + unsigned long GetStreamMaybeCopyAndReturnLengthImpl(const CPDF_Stream* stream, void* buffer, unsigned long buflen, @@ -360,9 +370,8 @@ } } -void ReportUnsupportedXFA(CPDF_Document* pDoc) { - // XFA Forms - if (!pDoc->GetExtension() && CPDF_InteractiveForm(pDoc).HasXFAForm()) +void ReportUnsupportedXFA(const CPDF_Document* pDoc) { + if (!pDoc->GetExtension() && DocHasXFA(pDoc)) RaiseUnsupportedError(FPDF_UNSP_DOC_XFAFORM); }
diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h index 66c47f5..51558fe 100644 --- a/fpdfsdk/cpdfsdk_helpers.h +++ b/fpdfsdk/cpdfsdk_helpers.h
@@ -263,7 +263,7 @@ void SetPDFUnsupportInfo(UNSUPPORT_INFO* unsp_info); void ReportUnsupportedFeatures(CPDF_Document* pDoc); -void ReportUnsupportedXFA(CPDF_Document* pDoc); +void ReportUnsupportedXFA(const CPDF_Document* pDoc); void CheckForUnsupportedAnnot(const CPDF_Annot* pAnnot); void ProcessParseError(CPDF_Parser::Error err);