Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp

Issue 2294383003: Use unsigned page indexes in CPDF_HintTables. (Closed)
Patch Set: Use unsigned page indexes in CPDF_HintTables. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_array.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_data_avail.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_data_avail.h"
(...skipping 17 matching lines...) Expand all
28 : m_pDataAvail(pDataAvail), 28 : m_pDataAvail(pDataAvail),
29 m_pLinearizedDict(pLinearized), 29 m_pLinearizedDict(pLinearized),
30 m_nFirstPageSharedObjs(0), 30 m_nFirstPageSharedObjs(0),
31 m_szFirstPageObjOffset(0) { 31 m_szFirstPageObjOffset(0) {
32 ASSERT(m_pLinearizedDict); 32 ASSERT(m_pLinearizedDict);
33 } 33 }
34 34
35 CPDF_HintTables::~CPDF_HintTables() {} 35 CPDF_HintTables::~CPDF_HintTables() {}
36 36
37 uint32_t CPDF_HintTables::GetItemLength( 37 uint32_t CPDF_HintTables::GetItemLength(
38 int index, 38 uint32_t index,
39 const std::vector<FX_FILESIZE>& szArray) { 39 const std::vector<FX_FILESIZE>& szArray) {
40 if (index < 0 || szArray.size() < 2 || 40 if (szArray.size() < 2 || index > szArray.size() - 2 ||
41 static_cast<size_t>(index) > szArray.size() - 2 ||
42 szArray[index] > szArray[index + 1]) { 41 szArray[index] > szArray[index + 1]) {
43 return 0; 42 return 0;
44 } 43 }
45 return szArray[index + 1] - szArray[index]; 44 return szArray[index + 1] - szArray[index];
46 } 45 }
47 46
48 bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { 47 bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) {
49 if (!hStream || hStream->IsEOF()) 48 if (!hStream || hStream->IsEOF())
50 return false; 49 return false;
51 50
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 346
348 hStream->ByteAlign(); 347 hStream->ByteAlign();
349 if (hStream->BitsRemaining() < dwSharedObjTotal) 348 if (hStream->BitsRemaining() < dwSharedObjTotal)
350 return false; 349 return false;
351 350
352 hStream->SkipBits(dwSharedObjTotal); 351 hStream->SkipBits(dwSharedObjTotal);
353 hStream->ByteAlign(); 352 hStream->ByteAlign();
354 return true; 353 return true;
355 } 354 }
356 355
357 bool CPDF_HintTables::GetPagePos(int index, 356 bool CPDF_HintTables::GetPagePos(uint32_t index,
358 FX_FILESIZE* szPageStartPos, 357 FX_FILESIZE* szPageStartPos,
359 FX_FILESIZE* szPageLength, 358 FX_FILESIZE* szPageLength,
360 uint32_t* dwObjNum) { 359 uint32_t* dwObjNum) {
361 if (index < 0)
362 return false;
363
364 *szPageStartPos = m_szPageOffsetArray[index]; 360 *szPageStartPos = m_szPageOffsetArray[index];
365 *szPageLength = GetItemLength(index, m_szPageOffsetArray); 361 *szPageLength = GetItemLength(index, m_szPageOffsetArray);
366 362
367 int nFirstPageObjNum = GetFirstPageObjectNumber(); 363 int nFirstPageObjNum = GetFirstPageObjectNumber();
368 if (nFirstPageObjNum < 0) 364 if (nFirstPageObjNum < 0)
369 return false; 365 return false;
370 366
371 int nFirstPageNum = GetFirstPageNumber(); 367 int nFirstPageNum = GetFirstPageNumber();
372 if (nFirstPageNum < 0) 368 if (nFirstPageNum < 0)
Tom Sepez 2016/09/01 16:16:27 Do we just want to use base's checked cast magin i
Lei Zhang 2016/09/01 17:58:21 Done.
373 return false; 369 return false;
374 370
375 if (index == nFirstPageNum) { 371 uint32_t dwFirstPageNum = static_cast<uint32_t>(nFirstPageNum);
372 if (index == dwFirstPageNum) {
376 *dwObjNum = nFirstPageObjNum; 373 *dwObjNum = nFirstPageObjNum;
377 return true; 374 return true;
378 } 375 }
379 376
380 // The object number of remaining pages starts from 1. 377 // The object number of remaining pages starts from 1.
381 *dwObjNum = 1; 378 *dwObjNum = 1;
382 for (int i = 0; i < index; ++i) { 379 for (uint32_t i = 0; i < index; ++i) {
383 if (i == nFirstPageNum) 380 if (i == dwFirstPageNum)
384 continue; 381 continue;
385 *dwObjNum += m_dwDeltaNObjsArray[i]; 382 *dwObjNum += m_dwDeltaNObjsArray[i];
386 } 383 }
387 return true; 384 return true;
388 } 385 }
389 386
390 CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( 387 CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage(
391 int index, 388 uint32_t index,
392 CPDF_DataAvail::DownloadHints* pHints) { 389 CPDF_DataAvail::DownloadHints* pHints) {
393 if (!pHints || index < 0) 390 if (!pHints)
394 return CPDF_DataAvail::DataError; 391 return CPDF_DataAvail::DataError;
395 392
396 if (index == GetFirstPageNumber()) 393 int nFirstPageNum = GetFirstPageNumber();
394 if (nFirstPageNum < 0)
395 return CPDF_DataAvail::DataError;
396
397 if (index == static_cast<uint32_t>(nFirstPageNum))
397 return CPDF_DataAvail::DataAvailable; 398 return CPDF_DataAvail::DataAvailable;
398 399
399 uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray); 400 uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray);
400 // If two pages have the same offset, it should be treated as an error. 401 // If two pages have the same offset, it should be treated as an error.
401 if (!dwLength) 402 if (!dwLength)
402 return CPDF_DataAvail::DataError; 403 return CPDF_DataAvail::DataError;
403 404
404 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints)) 405 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints))
405 return CPDF_DataAvail::DataNotAvailable; 406 return CPDF_DataAvail::DataNotAvailable;
406 407
407 // Download data of shared objects in the page. 408 // Download data of shared objects in the page.
408 uint32_t offset = 0; 409 uint32_t offset = 0;
409 for (int i = 0; i < index; ++i) 410 for (uint32_t i = 0; i < index; ++i)
410 offset += m_dwNSharedObjsArray[i]; 411 offset += m_dwNSharedObjsArray[i];
411 412
412 int nFirstPageObjNum = GetFirstPageObjectNumber(); 413 int nFirstPageObjNum = GetFirstPageObjectNumber();
413 if (nFirstPageObjNum < 0) 414 if (nFirstPageObjNum < 0)
414 return CPDF_DataAvail::DataError; 415 return CPDF_DataAvail::DataError;
415 416
416 uint32_t dwIndex = 0; 417 uint32_t dwIndex = 0;
417 uint32_t dwObjNum = 0; 418 uint32_t dwObjNum = 0;
418 for (uint32_t j = 0; j < m_dwNSharedObjsArray[index]; ++j) { 419 for (uint32_t j = 0; j < m_dwNSharedObjsArray[index]; ++j) {
419 dwIndex = m_dwIdentifierArray[offset + j]; 420 dwIndex = m_dwIdentifierArray[offset + j];
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 506 }
506 507
507 int CPDF_HintTables::ReadPrimaryHintStream(int index) const { 508 int CPDF_HintTables::ReadPrimaryHintStream(int index) const {
508 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); 509 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H");
509 if (!pRange) 510 if (!pRange)
510 return -1; 511 return -1;
511 512
512 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(index); 513 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(index);
513 return pStreamLen ? pStreamLen->GetInteger() : -1; 514 return pStreamLen ? pStreamLen->GetInteger() : -1;
514 } 515 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698