| 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" | 9 #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 const uint32_t kHeaderSize = 288; | 53 const uint32_t kHeaderSize = 288; |
| 54 if (hStream->BitsRemaining() < kHeaderSize) | 54 if (hStream->BitsRemaining() < kHeaderSize) |
| 55 return FALSE; | 55 return FALSE; |
| 56 | 56 |
| 57 // Item 1: The least number of objects in a page. | 57 // Item 1: The least number of objects in a page. |
| 58 uint32_t dwObjLeastNum = hStream->GetBits(32); | 58 uint32_t dwObjLeastNum = hStream->GetBits(32); |
| 59 | 59 |
| 60 // Item 2: The location of the first page's page object. | 60 // Item 2: The location of the first page's page object. |
| 61 uint32_t dwFirstObjLoc = hStream->GetBits(32); | 61 uint32_t dwFirstObjLoc = hStream->GetBits(32); |
| 62 if (dwFirstObjLoc > nStreamOffset) { | 62 if (dwFirstObjLoc > static_cast<uint32_t>(nStreamOffset)) { |
| 63 FX_SAFE_DWORD safeLoc = pdfium::base::checked_cast<uint32_t>(nStreamLen); | 63 FX_SAFE_DWORD safeLoc = pdfium::base::checked_cast<uint32_t>(nStreamLen); |
| 64 safeLoc += dwFirstObjLoc; | 64 safeLoc += dwFirstObjLoc; |
| 65 if (!safeLoc.IsValid()) | 65 if (!safeLoc.IsValid()) |
| 66 return FALSE; | 66 return FALSE; |
| 67 m_szFirstPageObjOffset = | 67 m_szFirstPageObjOffset = |
| 68 pdfium::base::checked_cast<FX_FILESIZE>(safeLoc.ValueOrDie()); | 68 pdfium::base::checked_cast<FX_FILESIZE>(safeLoc.ValueOrDie()); |
| 69 } else { | 69 } else { |
| 70 m_szFirstPageObjOffset = | 70 m_szFirstPageObjOffset = |
| 71 pdfium::base::checked_cast<FX_FILESIZE>(dwFirstObjLoc); | 71 pdfium::base::checked_cast<FX_FILESIZE>(dwFirstObjLoc); |
| 72 } | 72 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 const uint32_t kHeaderSize = 192; | 229 const uint32_t kHeaderSize = 192; |
| 230 if (hStream->BitsRemaining() < kHeaderSize) | 230 if (hStream->BitsRemaining() < kHeaderSize) |
| 231 return FALSE; | 231 return FALSE; |
| 232 | 232 |
| 233 // Item 1: The object number of the first object in the shared objects | 233 // Item 1: The object number of the first object in the shared objects |
| 234 // section. | 234 // section. |
| 235 uint32_t dwFirstSharedObjNum = hStream->GetBits(32); | 235 uint32_t dwFirstSharedObjNum = hStream->GetBits(32); |
| 236 | 236 |
| 237 // Item 2: The location of the first object in the shared objects section. | 237 // Item 2: The location of the first object in the shared objects section. |
| 238 uint32_t dwFirstSharedObjLoc = hStream->GetBits(32); | 238 uint32_t dwFirstSharedObjLoc = hStream->GetBits(32); |
| 239 if (dwFirstSharedObjLoc > nStreamOffset) | 239 if (dwFirstSharedObjLoc > static_cast<uint32_t>(nStreamOffset)) |
| 240 dwFirstSharedObjLoc += nStreamLen; | 240 dwFirstSharedObjLoc += nStreamLen; |
| 241 | 241 |
| 242 // Item 3: The number of shared object entries for the first page. | 242 // Item 3: The number of shared object entries for the first page. |
| 243 m_nFirstPageSharedObjs = hStream->GetBits(32); | 243 m_nFirstPageSharedObjs = hStream->GetBits(32); |
| 244 | 244 |
| 245 // Item 4: The number of shared object entries for the shared objects | 245 // Item 4: The number of shared object entries for the shared objects |
| 246 // section, including the number of shared object entries for the first page. | 246 // section, including the number of shared object entries for the first page. |
| 247 uint32_t dwSharedObjTotal = hStream->GetBits(32); | 247 uint32_t dwSharedObjTotal = hStream->GetBits(32); |
| 248 | 248 |
| 249 // Item 5: The number of bits needed to represent the greatest number of | 249 // Item 5: The number of bits needed to represent the greatest number of |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 380 |
| 381 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetDirectObjectBy("O"); | 381 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetDirectObjectBy("O"); |
| 382 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; | 382 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; |
| 383 if (nFirstPageObjNum < 0) | 383 if (nFirstPageObjNum < 0) |
| 384 return IPDF_DataAvail::DataError; | 384 return IPDF_DataAvail::DataError; |
| 385 | 385 |
| 386 uint32_t dwIndex = 0; | 386 uint32_t dwIndex = 0; |
| 387 uint32_t dwObjNum = 0; | 387 uint32_t dwObjNum = 0; |
| 388 for (uint32_t j = 0; j < m_dwNSharedObjsArray[index]; ++j) { | 388 for (uint32_t j = 0; j < m_dwNSharedObjsArray[index]; ++j) { |
| 389 dwIndex = m_dwIdentifierArray[offset + j]; | 389 dwIndex = m_dwIdentifierArray[offset + j]; |
| 390 if (dwIndex >= m_dwSharedObjNumArray.GetSize()) | 390 if (dwIndex >= static_cast<uint32_t>(m_dwSharedObjNumArray.GetSize())) |
| 391 return IPDF_DataAvail::DataNotAvailable; | 391 return IPDF_DataAvail::DataNotAvailable; |
| 392 | 392 |
| 393 dwObjNum = m_dwSharedObjNumArray[dwIndex]; | 393 dwObjNum = m_dwSharedObjNumArray[dwIndex]; |
| 394 if (dwObjNum >= nFirstPageObjNum && | 394 if (dwObjNum >= static_cast<uint32_t>(nFirstPageObjNum) && |
| 395 dwObjNum < nFirstPageObjNum + m_nFirstPageSharedObjs) { | 395 dwObjNum < |
| 396 static_cast<uint32_t>(nFirstPageObjNum) + m_nFirstPageSharedObjs) { |
| 396 continue; | 397 continue; |
| 397 } | 398 } |
| 398 | 399 |
| 399 dwLength = GetItemLength(dwIndex, m_szSharedObjOffsetArray); | 400 dwLength = GetItemLength(dwIndex, m_szSharedObjOffsetArray); |
| 400 // If two objects have the same offset, it should be treated as an error. | 401 // If two objects have the same offset, it should be treated as an error. |
| 401 if (!dwLength) | 402 if (!dwLength) |
| 402 return IPDF_DataAvail::DataError; | 403 return IPDF_DataAvail::DataError; |
| 403 | 404 |
| 404 if (!m_pDataAvail->IsDataAvail(m_szSharedObjOffsetArray[dwIndex], dwLength, | 405 if (!m_pDataAvail->IsDataAvail(m_szSharedObjOffsetArray[dwIndex], dwLength, |
| 405 pHints)) { | 406 pHints)) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 421 int shared_hint_table_offset = pOffset->GetInteger(); | 422 int shared_hint_table_offset = pOffset->GetInteger(); |
| 422 CPDF_StreamAcc acc; | 423 CPDF_StreamAcc acc; |
| 423 acc.LoadAllData(pHintStream); | 424 acc.LoadAllData(pHintStream); |
| 424 | 425 |
| 425 uint32_t size = acc.GetSize(); | 426 uint32_t size = acc.GetSize(); |
| 426 // The header section of page offset hint table is 36 bytes. | 427 // The header section of page offset hint table is 36 bytes. |
| 427 // The header section of shared object hint table is 24 bytes. | 428 // The header section of shared object hint table is 24 bytes. |
| 428 // Hint table has at least 60 bytes. | 429 // Hint table has at least 60 bytes. |
| 429 const uint32_t MIN_STREAM_LEN = 60; | 430 const uint32_t MIN_STREAM_LEN = 60; |
| 430 if (size < MIN_STREAM_LEN || shared_hint_table_offset <= 0 || | 431 if (size < MIN_STREAM_LEN || shared_hint_table_offset <= 0 || |
| 431 size < shared_hint_table_offset) { | 432 size < static_cast<uint32_t>(shared_hint_table_offset)) { |
| 432 return FALSE; | 433 return FALSE; |
| 433 } | 434 } |
| 434 | 435 |
| 435 CFX_BitStream bs; | 436 CFX_BitStream bs; |
| 436 bs.Init(acc.GetData(), size); | 437 bs.Init(acc.GetData(), size); |
| 437 return ReadPageHintTable(&bs) && | 438 return ReadPageHintTable(&bs) && |
| 438 ReadSharedObjHintTable(&bs, pdfium::base::checked_cast<uint32_t>( | 439 ReadSharedObjHintTable(&bs, pdfium::base::checked_cast<uint32_t>( |
| 439 shared_hint_table_offset)); | 440 shared_hint_table_offset)); |
| 440 } | 441 } |
| 441 | 442 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 461 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | 462 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); |
| 462 if (!pRange) | 463 if (!pRange) |
| 463 return -1; | 464 return -1; |
| 464 | 465 |
| 465 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(1); | 466 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(1); |
| 466 if (!pStreamLen) | 467 if (!pStreamLen) |
| 467 return -1; | 468 return -1; |
| 468 | 469 |
| 469 return pStreamLen->GetInteger(); | 470 return pStreamLen->GetInteger(); |
| 470 } | 471 } |
| OLD | NEW |