From a478dc5ca23b6f2f609b119cdc6b0336d1471d8c Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Mon, 23 Jan 2017 15:48:51 -0500 Subject: Fix CPDF_InterForm::CheckRequiredFields and its callers. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The method is used twice in fpdfsdk/cpdfsdk_interform.cpp and twice in fpdfsdk/javascript/Document.cpp, but not in a compatible way. Changed the method so that it now returns true when checks pass, which is the more natural thing to do, considering the name of the method. BUG=pdfium:659 Change-Id: Iacf3049f328df1d4db3fbfc995acf184230ebf48 Reviewed-on: https://pdfium-review.googlesource.com/2297 Commit-Queue: Nicolás Peña Reviewed-by: Tom Sepez --- core/fpdfdoc/cpdf_formfield.cpp | 16 ++++++---------- core/fpdfdoc/cpdf_formfield.h | 4 ++++ core/fpdfdoc/cpdf_interform.cpp | 12 +++++++----- core/fpdfdoc/cpdf_interform.h | 5 ++--- fpdfsdk/cpdfsdk_interform.cpp | 4 ++-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index b344327adc..b4aa90e2be 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -31,10 +31,6 @@ const int kFormListMultiSelect = 0x100; const int kFormComboEdit = 0x100; -const int kFormFieldReadOnly = 0x01; -const int kFormFieldRequired = 0x02; -const int kFormFieldNoExport = 0x04; - const int kFormRadioNoToggleOff = 0x100; const int kFormRadioUnison = 0x200; @@ -108,12 +104,12 @@ void CPDF_FormField::SyncFieldFlags() { ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() : 0; m_Flags = 0; - if (flags & 1) - m_Flags |= kFormFieldReadOnly; - if (flags & 2) - m_Flags |= kFormFieldRequired; - if (flags & 4) - m_Flags |= kFormFieldNoExport; + if (flags & FORMFLAG_READONLY) + m_Flags |= FORMFLAG_READONLY; + if (flags & FORMFLAG_REQUIRED) + m_Flags |= FORMFLAG_REQUIRED; + if (flags & FORMFLAG_NOEXPORT) + m_Flags |= FORMFLAG_NOEXPORT; if (type_name == "Btn") { if (flags & 0x8000) { diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h index 9a1ddc4599..42608b1122 100644 --- a/core/fpdfdoc/cpdf_formfield.h +++ b/core/fpdfdoc/cpdf_formfield.h @@ -25,6 +25,10 @@ #define FIELDTYPE_TEXTFIELD 6 #define FIELDTYPE_SIGNATURE 7 +#define FORMFLAG_READONLY 0x01 +#define FORMFLAG_REQUIRED 0x02 +#define FORMFLAG_NOEXPORT 0x04 + class CPDF_Dictionary; class CPDF_Font; class CPDF_FormControl; diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index 6cffea6222..127e542227 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -1157,7 +1157,7 @@ CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, return pControl; } -CPDF_FormField* CPDF_InterForm::CheckRequiredFields( +bool CPDF_InterForm::CheckRequiredFields( const std::vector* fields, bool bIncludeOrExclude) const { size_t nCount = m_pFieldTree->m_Root.CountFields(); @@ -1173,7 +1173,7 @@ CPDF_FormField* CPDF_InterForm::CheckRequiredFields( } uint32_t dwFlags = pField->GetFieldFlags(); // TODO(thestig): Look up these magic numbers and add constants for them. - if (dwFlags & 0x04) + if (dwFlags & FORMFLAG_NOEXPORT) continue; bool bFind = true; @@ -1181,11 +1181,13 @@ CPDF_FormField* CPDF_InterForm::CheckRequiredFields( bFind = pdfium::ContainsValue(*fields, pField); if (bIncludeOrExclude == bFind) { CPDF_Dictionary* pFieldDict = pField->m_pDict; - if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringFor("V").IsEmpty()) - return pField; + if ((dwFlags & FORMFLAG_REQUIRED) != 0 && + pFieldDict->GetStringFor("V").IsEmpty()) { + return false; + } } } - return nullptr; + return true; } std::unique_ptr CPDF_InterForm::ExportToFDF( diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h index b846973435..a42c4cef84 100644 --- a/core/fpdfdoc/cpdf_interform.h +++ b/core/fpdfdoc/cpdf_interform.h @@ -69,9 +69,8 @@ class CPDF_InterForm { CPDF_DefaultAppearance GetDefaultAppearance() const; int GetFormAlignment() const; - CPDF_FormField* CheckRequiredFields( - const std::vector* fields, - bool bIncludeOrExclude) const; + bool CheckRequiredFields(const std::vector* fields, + bool bIncludeOrExclude) const; std::unique_ptr ExportToFDF(const CFX_WideStringC& pdf_path, bool bSimpleFileSpec) const; diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 7b7718030b..b22ccb1684 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -427,13 +427,13 @@ bool CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { std::vector fields = GetFieldFromObjects(fieldObjects); if (!fields.empty()) { bool bIncludeOrExclude = !(dwFlags & 0x01); - if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) + if (!m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) return false; return SubmitFields(sDestination, fields, bIncludeOrExclude, false); } } - if (m_pInterForm->CheckRequiredFields(nullptr, true)) + if (!m_pInterForm->CheckRequiredFields(nullptr, true)) return false; return SubmitForm(sDestination, false); -- cgit v1.2.3