From 5ae6c564d16ce8b625df3d1950abc822f9ecc987 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 17 Oct 2018 17:57:51 +0000 Subject: Add CPDF_{Array,Dictionary}Locker to catch illegal iteration patterns. Move begin/end methods onto locker object which tracks whether iterators are in existence. Change-Id: Ia869f313fce48d10a0d0180d0cc083eed6ea1584 Reviewed-on: https://pdfium-review.googlesource.com/c/44070 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fpdfdoc/cpdf_formcontrol.cpp | 3 ++- core/fpdfdoc/cpdf_formfield.cpp | 3 ++- core/fpdfdoc/cpdf_interactiveform.cpp | 9 ++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'core/fpdfdoc') diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp index edd5fe566c..7ff0914590 100644 --- a/core/fpdfdoc/cpdf_formcontrol.cpp +++ b/core/fpdfdoc/cpdf_formcontrol.cpp @@ -48,7 +48,8 @@ ByteString CPDF_FormControl::GetOnStateName() const { if (!pN) return csOn; - for (const auto& it : *pN) { + CPDF_DictionaryLocker locker(pN); + for (const auto& it : locker) { if (it.first != "Off") return it.first; } diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index 2b06161b06..89030b4132 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -796,7 +796,8 @@ bool CPDF_FormField::IsOptionSelected(int iOptIndex) const { if (!pArray) return false; - for (const auto& pObj : *pArray) { + CPDF_ArrayLocker locker(pArray); + for (const auto& pObj : locker) { if (pObj->GetInteger() == iOptIndex) return true; } diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp index 403344c0ff..382d3dd314 100644 --- a/core/fpdfdoc/cpdf_interactiveform.cpp +++ b/core/fpdfdoc/cpdf_interactiveform.cpp @@ -154,7 +154,8 @@ CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, if (!pFonts) return nullptr; - for (const auto& it : *pFonts) { + CPDF_DictionaryLocker locker(pFonts); + for (const auto& it : locker) { const ByteString& csKey = it.first; if (!it.second) continue; @@ -194,7 +195,8 @@ bool FindFont(CPDF_Dictionary* pFormDict, if (!pFonts) return false; - for (const auto& it : *pFonts) { + CPDF_DictionaryLocker locker(pFonts); + for (const auto& it : locker) { const ByteString& csKey = it.first; if (!it.second) continue; @@ -230,7 +232,8 @@ bool FindFont(CPDF_Dictionary* pFormDict, if (csFontName.GetLength() > 0) csFontName.Remove(' '); - for (const auto& it : *pFonts) { + CPDF_DictionaryLocker locker(pFonts); + for (const auto& it : locker) { const ByteString& csKey = it.first; if (!it.second) continue; -- cgit v1.2.3