summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_ppo.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-06-29 06:55:50 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-29 06:55:50 +0000
commit20c3677acc37c959034d6111c0cab2e681b13717 (patch)
tree8c9e3ea9d3f495e2400f585493511f50830a533e /fpdfsdk/fpdf_ppo.cpp
parent5fbb98122c59d4bf0c830ee352ad4769d2decebf (diff)
downloadpdfium-20c3677acc37c959034d6111c0cab2e681b13717.tar.xz
Revert "Simplify CPDF_PageOrganizer::UpdateReference method."
This reverts commit 35ab1bd0328a244cc2f6dcde2822c8117738b01d. Reason for revert: Causing crashes and bad flattening. BUG=chromium:858921,chromium:858952 Original change's description: > Simplify CPDF_PageOrganizer::UpdateReference method. > > Change-Id: I52fe66472bdc2a61d7074f77627a3ee1d5646255 > Reviewed-on: https://pdfium-review.googlesource.com/35611 > Reviewed-by: dsinclair <dsinclair@chromium.org> > Commit-Queue: Art Snake <art-snake@yandex-team.ru> TBR=dsinclair@chromium.org,art-snake@yandex-team.ru Change-Id: I9a3635140867793e7109c15b64d66ec1d1a8b1f9 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://pdfium-review.googlesource.com/36550 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_ppo.cpp')
-rw-r--r--fpdfsdk/fpdf_ppo.cpp65
1 files changed, 47 insertions, 18 deletions
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index a35702efd9..8bbae7258d 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -20,7 +20,6 @@
#include "core/fpdfapi/parser/cpdf_name.h"
#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_object.h"
-#include "core/fpdfapi/parser/cpdf_object_walker.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
@@ -356,25 +355,55 @@ bool CPDF_PageOrganizer::PDFDocInit() {
bool CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
ObjectNumberMap* pObjNumberMap) {
- for (CPDF_NonConstObjectWalker walker(pObj);
- CPDF_Object* child = walker.GetNext();) {
- if (walker.dictionary_key() == "Parent" ||
- walker.dictionary_key() == "Prev" ||
- walker.dictionary_key() == "First") {
- walker.SkipWalkIntoCurrentObject();
- continue;
+ switch (pObj->GetType()) {
+ case CPDF_Object::REFERENCE: {
+ CPDF_Reference* pReference = pObj->AsReference();
+ uint32_t newobjnum = GetNewObjId(pObjNumberMap, pReference);
+ if (newobjnum == 0)
+ return false;
+ pReference->SetRef(dest(), newobjnum);
+ break;
}
- if (!child->IsReference())
- continue;
-
- CPDF_Reference* ref = ToReference(child);
-
- const uint32_t newobjnum = GetNewObjId(pObjNumberMap, ref);
- if (newobjnum == 0)
- return false;
-
- ref->SetRef(dest(), newobjnum);
+ case CPDF_Object::DICTIONARY: {
+ CPDF_Dictionary* pDict = pObj->AsDictionary();
+ auto it = pDict->begin();
+ while (it != pDict->end()) {
+ const ByteString& key = it->first;
+ CPDF_Object* pNextObj = it->second.get();
+ ++it;
+ if (key == "Parent" || key == "Prev" || key == "First")
+ continue;
+ if (!pNextObj)
+ return false;
+ if (!UpdateReference(pNextObj, pObjNumberMap))
+ pDict->RemoveFor(key);
+ }
+ break;
+ }
+ case CPDF_Object::ARRAY: {
+ CPDF_Array* pArray = pObj->AsArray();
+ for (size_t i = 0; i < pArray->GetCount(); ++i) {
+ CPDF_Object* pNextObj = pArray->GetObjectAt(i);
+ if (!pNextObj)
+ return false;
+ if (!UpdateReference(pNextObj, pObjNumberMap))
+ return false;
+ }
+ break;
+ }
+ case CPDF_Object::STREAM: {
+ CPDF_Stream* pStream = pObj->AsStream();
+ CPDF_Dictionary* pDict = pStream->GetDict();
+ if (!pDict)
+ return false;
+ if (!UpdateReference(pDict, pObjNumberMap))
+ return false;
+ break;
+ }
+ default:
+ break;
}
+
return true;
}