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

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

Issue 2298753003: Check first page number in CPDF_HintTables::ReadPageHintTable(). (Closed)
Patch Set: more 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return false; 158 return false;
159 159
160 dwPageLenArray.push_back(safePageLen.ValueOrDie()); 160 dwPageLenArray.push_back(safePageLen.ValueOrDie());
161 } 161 }
162 162
163 int nOffsetE = GetEndOfFirstPageOffset(); 163 int nOffsetE = GetEndOfFirstPageOffset();
164 if (nOffsetE < 0) 164 if (nOffsetE < 0)
165 return false; 165 return false;
166 166
167 int nFirstPageNum = GetFirstPageNumber(); 167 int nFirstPageNum = GetFirstPageNumber();
168 if (nFirstPageNum < 0 || nFirstPageNum > std::numeric_limits<int>::max() - 1)
169 return false;
170
168 for (int i = 0; i < nPages; ++i) { 171 for (int i = 0; i < nPages; ++i) {
169 if (i == nFirstPageNum) { 172 if (i == nFirstPageNum) {
170 m_szPageOffsetArray.push_back(m_szFirstPageObjOffset); 173 m_szPageOffsetArray.push_back(m_szFirstPageObjOffset);
171 } else if (i == nFirstPageNum + 1) { 174 } else if (i == nFirstPageNum + 1) {
172 if (i == 1) { 175 if (i == 1) {
173 m_szPageOffsetArray.push_back(nOffsetE); 176 m_szPageOffsetArray.push_back(nOffsetE);
174 } else { 177 } else {
175 m_szPageOffsetArray.push_back(m_szPageOffsetArray[i - 2] + 178 m_szPageOffsetArray.push_back(m_szPageOffsetArray[i - 2] +
176 dwPageLenArray[i - 2]); 179 dwPageLenArray[i - 2]);
177 } 180 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 347
345 hStream->ByteAlign(); 348 hStream->ByteAlign();
346 if (hStream->BitsRemaining() < dwSharedObjTotal) 349 if (hStream->BitsRemaining() < dwSharedObjTotal)
347 return false; 350 return false;
348 351
349 hStream->SkipBits(dwSharedObjTotal); 352 hStream->SkipBits(dwSharedObjTotal);
350 hStream->ByteAlign(); 353 hStream->ByteAlign();
351 return true; 354 return true;
352 } 355 }
353 356
354 bool CPDF_HintTables::GetPagePos(int index, 357 bool CPDF_HintTables::GetPagePos(int index,
Tom Sepez 2016/09/01 00:06:51 nit: can index at least be unsigned?
Lei Zhang 2016/09/01 00:11:30 Maybe. I will in a separate CL. Need to check the
355 FX_FILESIZE* szPageStartPos, 358 FX_FILESIZE* szPageStartPos,
356 FX_FILESIZE* szPageLength, 359 FX_FILESIZE* szPageLength,
357 uint32_t* dwObjNum) { 360 uint32_t* dwObjNum) {
361 if (index < 0)
362 return false;
363
358 *szPageStartPos = m_szPageOffsetArray[index]; 364 *szPageStartPos = m_szPageOffsetArray[index];
359 *szPageLength = GetItemLength(index, m_szPageOffsetArray); 365 *szPageLength = GetItemLength(index, m_szPageOffsetArray);
360 366
361 int nFirstPageObjNum = GetFirstPageObjectNumber(); 367 int nFirstPageObjNum = GetFirstPageObjectNumber();
362 if (nFirstPageObjNum < 0) 368 if (nFirstPageObjNum < 0)
363 return false; 369 return false;
364 370
365 int nFirstPageNum = GetFirstPageNumber(); 371 int nFirstPageNum = GetFirstPageNumber();
372 if (nFirstPageNum < 0)
373 return false;
374
366 if (index == nFirstPageNum) { 375 if (index == nFirstPageNum) {
367 *dwObjNum = nFirstPageObjNum; 376 *dwObjNum = nFirstPageObjNum;
368 return true; 377 return true;
369 } 378 }
370 379
371 // The object number of remaining pages starts from 1. 380 // The object number of remaining pages starts from 1.
372 *dwObjNum = 1; 381 *dwObjNum = 1;
373 for (int i = 0; i < index; ++i) { 382 for (int i = 0; i < index; ++i) {
374 if (i == nFirstPageNum) 383 if (i == nFirstPageNum)
375 continue; 384 continue;
376 *dwObjNum += m_dwDeltaNObjsArray[i]; 385 *dwObjNum += m_dwDeltaNObjsArray[i];
377 } 386 }
378 return true; 387 return true;
379 } 388 }
380 389
381 CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( 390 CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage(
382 int index, 391 int index,
383 CPDF_DataAvail::DownloadHints* pHints) { 392 CPDF_DataAvail::DownloadHints* pHints) {
Tom Sepez 2016/09/01 00:06:51 nit: same here.
384 if (!pHints) 393 if (!pHints || index < 0)
385 return CPDF_DataAvail::DataError; 394 return CPDF_DataAvail::DataError;
386 395
387 int nFirstAvailPage = GetFirstPageNumber(); 396 if (index == GetFirstPageNumber())
388 if (index == nFirstAvailPage)
389 return CPDF_DataAvail::DataAvailable; 397 return CPDF_DataAvail::DataAvailable;
390 398
391 uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray); 399 uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray);
392 // If two pages have the same offset, it should be treated as an error. 400 // If two pages have the same offset, it should be treated as an error.
393 if (!dwLength) 401 if (!dwLength)
394 return CPDF_DataAvail::DataError; 402 return CPDF_DataAvail::DataError;
395 403
396 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints)) 404 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints))
397 return CPDF_DataAvail::DataNotAvailable; 405 return CPDF_DataAvail::DataNotAvailable;
398 406
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 505 }
498 506
499 int CPDF_HintTables::ReadPrimaryHintStream(int index) const { 507 int CPDF_HintTables::ReadPrimaryHintStream(int index) const {
500 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); 508 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H");
501 if (!pRange) 509 if (!pRange)
502 return -1; 510 return -1;
503 511
504 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(index); 512 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(index);
505 return pStreamLen ? pStreamLen->GetInteger() : -1; 513 return pStreamLen ? pStreamLen->GetInteger() : -1;
506 } 514 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698