| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright 2016 PDFium Authors. All rights reserved. |  | 
| 2 // Use of this source code is governed by a BSD-style license that can be |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |  | 
| 6 |  | 
| 7 #include "core/fpdfapi/parser/cpdf_linearized.h" |  | 
| 8 |  | 
| 9 #include "core/fpdfapi/parser/cpdf_array.h" |  | 
| 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" |  | 
| 11 #include "core/fpdfapi/parser/cpdf_number.h" |  | 
| 12 #include "third_party/base/ptr_util.h" |  | 
| 13 |  | 
| 14 namespace { |  | 
| 15 |  | 
| 16 template <class T> |  | 
| 17 bool IsValidNumericDictionaryValue(const CPDF_Dictionary* pDict, |  | 
| 18                                    const char* key, |  | 
| 19                                    T min_value, |  | 
| 20                                    bool must_exist = true) { |  | 
| 21   if (!pDict->KeyExist(key)) |  | 
| 22     return !must_exist; |  | 
| 23   const CPDF_Number* pNum = ToNumber(pDict->GetObjectFor(key)); |  | 
| 24   if (!pNum || !pNum->IsInteger()) |  | 
| 25     return false; |  | 
| 26   const int raw_value = pNum->GetInteger(); |  | 
| 27   if (!pdfium::base::IsValueInRangeForNumericType<T>(raw_value)) |  | 
| 28     return false; |  | 
| 29   return static_cast<T>(raw_value) >= min_value; |  | 
| 30 } |  | 
| 31 |  | 
| 32 }  // namespace |  | 
| 33 |  | 
| 34 // static |  | 
| 35 std::unique_ptr<CPDF_Linearized> CPDF_Linearized::CreateForObject( |  | 
| 36     std::unique_ptr<CPDF_Object> pObj) { |  | 
| 37   auto pDict = ToDictionary(std::move(pObj)); |  | 
| 38   if (!pDict || !pDict->KeyExist("Linearized") || |  | 
| 39       !IsValidNumericDictionaryValue<FX_FILESIZE>(pDict.get(), "L", 1) || |  | 
| 40       !IsValidNumericDictionaryValue<uint32_t>(pDict.get(), "P", 0, false) || |  | 
| 41       !IsValidNumericDictionaryValue<FX_FILESIZE>(pDict.get(), "T", 1) || |  | 
| 42       !IsValidNumericDictionaryValue<uint32_t>(pDict.get(), "N", 0) || |  | 
| 43       !IsValidNumericDictionaryValue<FX_FILESIZE>(pDict.get(), "E", 1) || |  | 
| 44       !IsValidNumericDictionaryValue<uint32_t>(pDict.get(), "O", 1)) |  | 
| 45     return nullptr; |  | 
| 46   return pdfium::WrapUnique(new CPDF_Linearized(pDict.get())); |  | 
| 47 } |  | 
| 48 |  | 
| 49 CPDF_Linearized::CPDF_Linearized(const CPDF_Dictionary* pDict) { |  | 
| 50   if (!pDict) |  | 
| 51     return; |  | 
| 52   m_szFileSize = pDict->GetIntegerFor("L"); |  | 
| 53   m_dwFirstPageNo = pDict->GetIntegerFor("P"); |  | 
| 54   m_szLastXRefOffset = pDict->GetIntegerFor("T"); |  | 
| 55   m_PageCount = pDict->GetIntegerFor("N"); |  | 
| 56   m_szFirstPageEndOffset = pDict->GetIntegerFor("E"); |  | 
| 57   m_FirstPageObjNum = pDict->GetIntegerFor("O"); |  | 
| 58   const CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H"); |  | 
| 59   const size_t nHintStreamSize = |  | 
| 60       pHintStreamRange ? pHintStreamRange->GetCount() : 0; |  | 
| 61   if (nHintStreamSize == 2 || nHintStreamSize == 4) { |  | 
| 62     m_szHintStart = std::max(pHintStreamRange->GetIntegerAt(0), 0); |  | 
| 63     m_szHintLength = std::max(pHintStreamRange->GetIntegerAt(1), 0); |  | 
| 64   } |  | 
| 65 } |  | 
| 66 |  | 
| 67 CPDF_Linearized::~CPDF_Linearized() {} |  | 
| 68 |  | 
| 69 bool CPDF_Linearized::HasHintTable() const { |  | 
| 70   return GetPageCount() > 1 && GetHintStart() > 0 && GetHintLength() > 0; |  | 
| 71 } |  | 
| OLD | NEW | 
|---|