OLD | NEW |
1 // Copyright 2016 The PDFium Authors. All rights reserved. | 1 // Copyright 2016 The 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 <cstdint> | 5 #include <cstdint> |
6 | 6 |
7 #include "core/fpdfapi/parser/cpdf_array.h" | 7 #include "core/fpdfapi/parser/cpdf_array.h" |
| 8 #include "core/fpdfapi/parser/cpdf_boolean.h" |
8 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 9 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
9 #include "core/fpdfapi/parser/cpdf_hint_tables.h" | 10 #include "core/fpdfapi/parser/cpdf_hint_tables.h" |
10 #include "core/fpdfapi/parser/cpdf_linearized_header.h" | 11 #include "core/fpdfapi/parser/cpdf_linearized_header.h" |
11 #include "core/fpdfapi/parser/cpdf_number.h" | 12 #include "core/fpdfapi/parser/cpdf_number.h" |
12 #include "third_party/base/ptr_util.h" | 13 #include "third_party/base/ptr_util.h" |
13 | 14 |
14 int32_t GetData(const int32_t** data32, const uint8_t** data, size_t* size) { | 15 int32_t GetData(const int32_t** data32, const uint8_t** data, size_t* size) { |
15 const int32_t* ret = *data32; | 16 const int32_t* ret = *data32; |
16 ++(*data32); | 17 ++(*data32); |
17 *data += 4; | 18 *data += 4; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // Need 28 bytes for |linearized_dict|. | 56 // Need 28 bytes for |linearized_dict|. |
56 // The header section of page offset hint table is 36 bytes. | 57 // The header section of page offset hint table is 36 bytes. |
57 // The header section of shared object hint table is 24 bytes. | 58 // The header section of shared object hint table is 24 bytes. |
58 if (size < 28 + 36 + 24) | 59 if (size < 28 + 36 + 24) |
59 return 0; | 60 return 0; |
60 | 61 |
61 const int32_t* data32 = reinterpret_cast<const int32_t*>(data); | 62 const int32_t* data32 = reinterpret_cast<const int32_t*>(data); |
62 | 63 |
63 auto linearized_dict = pdfium::MakeUnique<CPDF_Dictionary>(); | 64 auto linearized_dict = pdfium::MakeUnique<CPDF_Dictionary>(); |
64 // Set initial value. | 65 // Set initial value. |
65 linearized_dict->SetBooleanFor("Linearized", true); | 66 linearized_dict->SetNewFor<CPDF_Boolean>("Linearized", true); |
66 // Set first page end offset | 67 // Set first page end offset |
67 linearized_dict->SetIntegerFor("E", GetData(&data32, &data, &size)); | 68 linearized_dict->SetNewFor<CPDF_Number>("E", GetData(&data32, &data, &size)); |
68 // Set page count | 69 // Set page count |
69 linearized_dict->SetIntegerFor("N", GetData(&data32, &data, &size)); | 70 linearized_dict->SetNewFor<CPDF_Number>("N", GetData(&data32, &data, &size)); |
70 // Set first page obj num | 71 // Set first page obj num |
71 linearized_dict->SetIntegerFor("O", GetData(&data32, &data, &size)); | 72 linearized_dict->SetNewFor<CPDF_Number>("O", GetData(&data32, &data, &size)); |
72 // Set first page no | 73 // Set first page no |
73 linearized_dict->SetIntegerFor("P", GetData(&data32, &data, &size)); | 74 linearized_dict->SetNewFor<CPDF_Number>("P", GetData(&data32, &data, &size)); |
74 | 75 |
75 auto hint_info = pdfium::MakeUnique<CPDF_Array>(); | 76 auto hint_info = pdfium::MakeUnique<CPDF_Array>(); |
76 // Add primary hint stream offset | 77 // Add primary hint stream offset |
77 hint_info->AddNew<CPDF_Number>(GetData(&data32, &data, &size)); | 78 hint_info->AddNew<CPDF_Number>(GetData(&data32, &data, &size)); |
78 // Add primary hint stream size | 79 // Add primary hint stream size |
79 hint_info->AddNew<CPDF_Number>(GetData(&data32, &data, &size)); | 80 hint_info->AddNew<CPDF_Number>(GetData(&data32, &data, &size)); |
80 // Set hint stream info. | 81 // Set hint stream info. |
81 linearized_dict->SetFor("H", hint_info.release()); | 82 linearized_dict->SetFor("H", std::move(hint_info)); |
82 | 83 |
83 const int shared_hint_table_offset = GetData(&data32, &data, &size); | 84 const int shared_hint_table_offset = GetData(&data32, &data, &size); |
84 | 85 |
85 { | 86 { |
86 FakeLinearized linearized(linearized_dict.get()); | 87 FakeLinearized linearized(linearized_dict.get()); |
87 HintTableForFuzzing hint_table(&linearized, shared_hint_table_offset); | 88 HintTableForFuzzing hint_table(&linearized, shared_hint_table_offset); |
88 hint_table.Fuzz(data, size); | 89 hint_table.Fuzz(data, size); |
89 } | 90 } |
90 return 0; | 91 return 0; |
91 } | 92 } |
OLD | NEW |