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/include/cpdf_data_avail.h" | 9 #include "core/fpdfapi/fpdf_parser/include/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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { | 421 FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { |
422 if (!pHintStream || !m_pLinearizedDict) | 422 if (!pHintStream || !m_pLinearizedDict) |
423 return FALSE; | 423 return FALSE; |
424 | 424 |
425 CPDF_Dictionary* pDict = pHintStream->GetDict(); | 425 CPDF_Dictionary* pDict = pHintStream->GetDict(); |
426 CPDF_Object* pOffset = pDict ? pDict->GetObjectBy("S") : nullptr; | 426 CPDF_Object* pOffset = pDict ? pDict->GetObjectBy("S") : nullptr; |
427 if (!pOffset || !pOffset->IsNumber()) | 427 if (!pOffset || !pOffset->IsNumber()) |
428 return FALSE; | 428 return FALSE; |
429 | 429 |
430 int shared_hint_table_offset = pOffset->GetInteger(); | 430 int shared_hint_table_offset = pOffset->GetInteger(); |
| 431 if (shared_hint_table_offset <= 0) |
| 432 return FALSE; |
| 433 |
431 CPDF_StreamAcc acc; | 434 CPDF_StreamAcc acc; |
432 acc.LoadAllData(pHintStream); | 435 acc.LoadAllData(pHintStream); |
433 | 436 |
434 uint32_t size = acc.GetSize(); | 437 uint32_t size = acc.GetSize(); |
435 // The header section of page offset hint table is 36 bytes. | 438 // The header section of page offset hint table is 36 bytes. |
436 // The header section of shared object hint table is 24 bytes. | 439 // The header section of shared object hint table is 24 bytes. |
437 // Hint table has at least 60 bytes. | 440 // Hint table has at least 60 bytes. |
438 const uint32_t MIN_STREAM_LEN = 60; | 441 const uint32_t kMinStreamLength = 60; |
439 if (size < MIN_STREAM_LEN || shared_hint_table_offset <= 0 || | 442 if (size < kMinStreamLength) |
440 size < static_cast<uint32_t>(shared_hint_table_offset)) { | 443 return FALSE; |
| 444 |
| 445 FX_SAFE_UINT32 safe_shared_hint_table_offset = shared_hint_table_offset; |
| 446 if (!safe_shared_hint_table_offset.IsValid() || |
| 447 size < safe_shared_hint_table_offset.ValueOrDie()) { |
441 return FALSE; | 448 return FALSE; |
442 } | 449 } |
443 | 450 |
444 CFX_BitStream bs; | 451 CFX_BitStream bs; |
445 bs.Init(acc.GetData(), size); | 452 bs.Init(acc.GetData(), size); |
446 return ReadPageHintTable(&bs) && | 453 return ReadPageHintTable(&bs) && |
447 ReadSharedObjHintTable(&bs, pdfium::base::checked_cast<uint32_t>( | 454 ReadSharedObjHintTable(&bs, shared_hint_table_offset); |
448 shared_hint_table_offset)); | |
449 } | 455 } |
450 | 456 |
451 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const { | 457 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const { |
452 if (!m_pLinearizedDict) | 458 if (!m_pLinearizedDict) |
453 return -1; | 459 return -1; |
454 | 460 |
455 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | 461 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); |
456 if (!pRange) | 462 if (!pRange) |
457 return -1; | 463 return -1; |
458 | 464 |
(...skipping 11 matching lines...) Expand all Loading... |
470 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | 476 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); |
471 if (!pRange) | 477 if (!pRange) |
472 return -1; | 478 return -1; |
473 | 479 |
474 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(1); | 480 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(1); |
475 if (!pStreamLen) | 481 if (!pStreamLen) |
476 return -1; | 482 return -1; |
477 | 483 |
478 return pStreamLen->GetInteger(); | 484 return pStreamLen->GetInteger(); |
479 } | 485 } |
OLD | NEW |