diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-10-17 17:57:51 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-17 17:57:51 +0000 |
commit | 5ae6c564d16ce8b625df3d1950abc822f9ecc987 (patch) | |
tree | 96bb64df3166e46db397e405789588bf8dc53842 /core/fpdfapi/parser/cpdf_object_walker.cpp | |
parent | 785a26dc649af80c593f899a606dff4dae7c48fd (diff) | |
download | pdfium-5ae6c564d16ce8b625df3d1950abc822f9ecc987.tar.xz |
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 <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_object_walker.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_object_walker.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/core/fpdfapi/parser/cpdf_object_walker.cpp b/core/fpdfapi/parser/cpdf_object_walker.cpp index 6d6d489e02..f3e1062d83 100644 --- a/core/fpdfapi/parser/cpdf_object_walker.cpp +++ b/core/fpdfapi/parser/cpdf_object_walker.cpp @@ -37,11 +37,11 @@ class StreamIterator final : public CPDF_ObjectWalker::SubobjectIterator { class DictionaryIterator final : public CPDF_ObjectWalker::SubobjectIterator { public: explicit DictionaryIterator(const CPDF_Dictionary* dictionary) - : SubobjectIterator(dictionary) {} + : SubobjectIterator(dictionary), locker_(dictionary) {} ~DictionaryIterator() override {} bool IsFinished() const override { - return IsStarted() && dict_iterator_ == object()->GetDict()->end(); + return IsStarted() && dict_iterator_ == locker_.end(); } const CPDF_Object* IncrementImpl() override { @@ -55,24 +55,26 @@ class DictionaryIterator final : public CPDF_ObjectWalker::SubobjectIterator { void Start() override { ASSERT(!IsStarted()); - dict_iterator_ = object()->GetDict()->begin(); + dict_iterator_ = locker_.begin(); } ByteString dict_key() const { return dict_key_; } private: CPDF_Dictionary::const_iterator dict_iterator_; + CPDF_DictionaryLocker locker_; ByteString dict_key_; }; class ArrayIterator final : public CPDF_ObjectWalker::SubobjectIterator { public: - explicit ArrayIterator(const CPDF_Array* array) : SubobjectIterator(array) {} + explicit ArrayIterator(const CPDF_Array* array) + : SubobjectIterator(array), locker_(array) {} ~ArrayIterator() override {} bool IsFinished() const override { - return IsStarted() && arr_iterator_ == object()->AsArray()->end(); + return IsStarted() && arr_iterator_ == locker_.end(); } const CPDF_Object* IncrementImpl() override { @@ -83,10 +85,11 @@ class ArrayIterator final : public CPDF_ObjectWalker::SubobjectIterator { return result; } - void Start() override { arr_iterator_ = object()->AsArray()->begin(); } + void Start() override { arr_iterator_ = locker_.begin(); } public: CPDF_Array::const_iterator arr_iterator_; + CPDF_ArrayLocker locker_; }; } // namespace |