| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/fpdfapi/parser/cpdf_array.h" | 5 #include "core/fpdfapi/parser/cpdf_array.h" |
| 6 #include "core/fpdfapi/parser/cpdf_boolean.h" | 6 #include "core/fpdfapi/parser/cpdf_boolean.h" |
| 7 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 7 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 8 #include "core/fpdfapi/parser/cpdf_name.h" | 8 #include "core/fpdfapi/parser/cpdf_name.h" |
| 9 #include "core/fpdfapi/parser/cpdf_null.h" | 9 #include "core/fpdfapi/parser/cpdf_null.h" |
| 10 #include "core/fpdfapi/parser/cpdf_number.h" | 10 #include "core/fpdfapi/parser/cpdf_number.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 stream_obj, null_obj}; | 83 stream_obj, null_obj}; |
| 84 m_DirectObjTypes = { | 84 m_DirectObjTypes = { |
| 85 CPDF_Object::BOOLEAN, CPDF_Object::BOOLEAN, CPDF_Object::NUMBER, | 85 CPDF_Object::BOOLEAN, CPDF_Object::BOOLEAN, CPDF_Object::NUMBER, |
| 86 CPDF_Object::NUMBER, CPDF_Object::STRING, CPDF_Object::STRING, | 86 CPDF_Object::NUMBER, CPDF_Object::STRING, CPDF_Object::STRING, |
| 87 CPDF_Object::NAME, CPDF_Object::ARRAY, CPDF_Object::DICTIONARY, | 87 CPDF_Object::NAME, CPDF_Object::ARRAY, CPDF_Object::DICTIONARY, |
| 88 CPDF_Object::STREAM, CPDF_Object::NULLOBJ}; | 88 CPDF_Object::STREAM, CPDF_Object::NULLOBJ}; |
| 89 for (size_t i = 0; i < FX_ArraySize(objs); ++i) | 89 for (size_t i = 0; i < FX_ArraySize(objs); ++i) |
| 90 m_DirectObjs.emplace_back(objs[i]); | 90 m_DirectObjs.emplace_back(objs[i]); |
| 91 | 91 |
| 92 // Indirect references to indirect objects. | 92 // Indirect references to indirect objects. |
| 93 m_ObjHolder.reset(new CPDF_IndirectObjectHolder()); | 93 m_ObjHolder = pdfium::MakeUnique<CPDF_IndirectObjectHolder>(); |
| 94 m_IndirectObjs = { | 94 m_IndirectObjs = {m_ObjHolder->AddIndirectObject(boolean_true_obj->Clone()), |
| 95 boolean_true_obj->Clone().release(), number_int_obj->Clone().release(), | 95 m_ObjHolder->AddIndirectObject(number_int_obj->Clone()), |
| 96 str_spec_obj->Clone().release(), name_obj->Clone().release(), | 96 m_ObjHolder->AddIndirectObject(str_spec_obj->Clone()), |
| 97 m_ArrayObj->Clone().release(), m_DictObj->Clone().release(), | 97 m_ObjHolder->AddIndirectObject(name_obj->Clone()), |
| 98 stream_obj->Clone().release()}; | 98 m_ObjHolder->AddIndirectObject(m_ArrayObj->Clone()), |
| 99 for (size_t i = 0; i < m_IndirectObjs.size(); ++i) { | 99 m_ObjHolder->AddIndirectObject(m_DictObj->Clone()), |
| 100 m_ObjHolder->AddIndirectObject(m_IndirectObjs[i]); | 100 m_ObjHolder->AddIndirectObject(stream_obj->Clone())}; |
| 101 m_RefObjs.emplace_back(new CPDF_Reference( | 101 for (CPDF_Object* pObj : m_IndirectObjs) { |
| 102 m_ObjHolder.get(), m_IndirectObjs[i]->GetObjNum())); | 102 m_RefObjs.emplace_back( |
| 103 new CPDF_Reference(m_ObjHolder.get(), pObj->GetObjNum())); |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 106 bool Equal(const CPDF_Object* obj1, const CPDF_Object* obj2) { | 107 bool Equal(const CPDF_Object* obj1, const CPDF_Object* obj2) { |
| 107 if (obj1 == obj2) | 108 if (obj1 == obj2) |
| 108 return true; | 109 return true; |
| 109 if (!obj1 || !obj2 || obj1->GetType() != obj2->GetType()) | 110 if (!obj1 || !obj2 || obj1->GetType() != obj2->GetType()) |
| 110 return false; | 111 return false; |
| 111 switch (obj1->GetType()) { | 112 switch (obj1->GetType()) { |
| 112 case CPDF_Object::BOOLEAN: | 113 case CPDF_Object::BOOLEAN: |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 ASSERT_TRUE(cloned_stream); | 831 ASSERT_TRUE(cloned_stream); |
| 831 CPDF_Object* cloned_dict = cloned_stream->GetDict(); | 832 CPDF_Object* cloned_dict = cloned_stream->GetDict(); |
| 832 ASSERT_TRUE(cloned_dict); | 833 ASSERT_TRUE(cloned_dict); |
| 833 ASSERT_TRUE(cloned_dict->IsDictionary()); | 834 ASSERT_TRUE(cloned_dict->IsDictionary()); |
| 834 // Recursively referenced object is not cloned. | 835 // Recursively referenced object is not cloned. |
| 835 EXPECT_EQ(nullptr, cloned_dict->AsDictionary()->GetObjectFor("stream")); | 836 EXPECT_EQ(nullptr, cloned_dict->AsDictionary()->GetObjectFor("stream")); |
| 836 } | 837 } |
| 837 { | 838 { |
| 838 CPDF_IndirectObjectHolder objects_holder; | 839 CPDF_IndirectObjectHolder objects_holder; |
| 839 // Create an object with a reference loop. | 840 // Create an object with a reference loop. |
| 840 CPDF_Dictionary* dict_obj = new CPDF_Dictionary(); | 841 CPDF_Dictionary* dict_obj = objects_holder.NewIndirect<CPDF_Dictionary>(); |
| 841 CPDF_Array* arr_obj = new CPDF_Array; | 842 std::unique_ptr<CPDF_Array> arr_obj = pdfium::MakeUnique<CPDF_Array>(); |
| 842 objects_holder.AddIndirectObject(dict_obj); | |
| 843 EXPECT_EQ(1u, dict_obj->GetObjNum()); | |
| 844 dict_obj->SetFor("arr", arr_obj); | |
| 845 arr_obj->InsertAt( | 843 arr_obj->InsertAt( |
| 846 0, new CPDF_Reference(&objects_holder, dict_obj->GetObjNum())); | 844 0, new CPDF_Reference(&objects_holder, dict_obj->GetObjNum())); |
| 847 CPDF_Object* elem0 = arr_obj->GetObjectAt(0); | 845 CPDF_Object* elem0 = arr_obj->GetObjectAt(0); |
| 846 dict_obj->SetFor("arr", arr_obj.release()); |
| 847 EXPECT_EQ(1u, dict_obj->GetObjNum()); |
| 848 ASSERT_TRUE(elem0); | 848 ASSERT_TRUE(elem0); |
| 849 ASSERT_TRUE(elem0->IsReference()); | 849 ASSERT_TRUE(elem0->IsReference()); |
| 850 EXPECT_EQ(1u, elem0->AsReference()->GetRefObjNum()); | 850 EXPECT_EQ(1u, elem0->AsReference()->GetRefObjNum()); |
| 851 EXPECT_EQ(dict_obj, elem0->AsReference()->GetDirect()); | 851 EXPECT_EQ(dict_obj, elem0->AsReference()->GetDirect()); |
| 852 | 852 |
| 853 // Clone this object to see whether stack overflow will be triggered. | 853 // Clone this object to see whether stack overflow will be triggered. |
| 854 std::unique_ptr<CPDF_Dictionary> cloned_dict = | 854 std::unique_ptr<CPDF_Dictionary> cloned_dict = |
| 855 ToDictionary(dict_obj->CloneDirectObject()); | 855 ToDictionary(dict_obj->CloneDirectObject()); |
| 856 // Cloned object should be the same as the original. | 856 // Cloned object should be the same as the original. |
| 857 ASSERT_TRUE(cloned_dict); | 857 ASSERT_TRUE(cloned_dict); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 871 dict->SetFor("clams", pObj); | 871 dict->SetFor("clams", pObj); |
| 872 dict->ConvertToIndirectObjectFor("clams", &objects_holder); | 872 dict->ConvertToIndirectObjectFor("clams", &objects_holder); |
| 873 CPDF_Object* pRef = dict->GetObjectFor("clams"); | 873 CPDF_Object* pRef = dict->GetObjectFor("clams"); |
| 874 CPDF_Object* pNum = dict->GetDirectObjectFor("clams"); | 874 CPDF_Object* pNum = dict->GetDirectObjectFor("clams"); |
| 875 EXPECT_TRUE(pRef->IsReference()); | 875 EXPECT_TRUE(pRef->IsReference()); |
| 876 EXPECT_TRUE(pNum->IsNumber()); | 876 EXPECT_TRUE(pNum->IsNumber()); |
| 877 EXPECT_NE(pObj, pRef); | 877 EXPECT_NE(pObj, pRef); |
| 878 EXPECT_EQ(pObj, pNum); | 878 EXPECT_EQ(pObj, pNum); |
| 879 EXPECT_EQ(42, dict->GetIntegerFor("clams")); | 879 EXPECT_EQ(42, dict->GetIntegerFor("clams")); |
| 880 } | 880 } |
| OLD | NEW |