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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 1558093002: Exit infinite loops for cross reference loading (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 11 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 | fpdfsdk/src/fpdfview_embeddertest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "parser_int.h" 7 #include "parser_int.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 return FALSE; 370 return FALSE;
371 } 371 }
372 m_ObjectInfo[0].pos = 0; 372 m_ObjectInfo[0].pos = 0;
373 m_V5Type.SetSize(xrefsize); 373 m_V5Type.SetSize(xrefsize);
374 CFX_FileSizeArray CrossRefList, XRefStreamList; 374 CFX_FileSizeArray CrossRefList, XRefStreamList;
375 CrossRefList.Add(xrefpos); 375 CrossRefList.Add(xrefpos);
376 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm")); 376 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm"));
377 if (!CheckDirectType(m_pTrailer, "Prev", PDFOBJ_NUMBER)) { 377 if (!CheckDirectType(m_pTrailer, "Prev", PDFOBJ_NUMBER)) {
378 return FALSE; 378 return FALSE;
379 } 379 }
380 FX_FILESIZE newxrefpos = GetDirectInteger(m_pTrailer, "Prev"); 380
381 if (newxrefpos == xrefpos) { 381 std::set<FX_FILESIZE> seen_xrefpos;
382 return FALSE; 382 seen_xrefpos.insert(xrefpos);
383 } 383 xrefpos = GetDirectInteger(m_pTrailer, "Prev");
384 xrefpos = newxrefpos;
385 while (xrefpos) { 384 while (xrefpos) {
385 // Check for circular references.
386 if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end())
Lei Zhang 2016/01/05 03:30:27 I added pdfium::ContainsKey() recently. You can us
Wei Li 2016/01/05 19:52:00 Done.
387 return FALSE;
388 seen_xrefpos.insert(xrefpos);
386 CrossRefList.InsertAt(0, xrefpos); 389 CrossRefList.InsertAt(0, xrefpos);
387 LoadCrossRefV4(xrefpos, 0, TRUE); 390 LoadCrossRefV4(xrefpos, 0, TRUE);
388 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( 391 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict(
389 LoadTrailerV4()); 392 LoadTrailerV4());
390 if (!pDict) 393 if (!pDict)
391 return FALSE; 394 return FALSE;
392 395
393 if (!CheckDirectType(pDict.get(), "Prev", PDFOBJ_NUMBER)) 396 if (!CheckDirectType(pDict.get(), "Prev", PDFOBJ_NUMBER))
394 return FALSE; 397 return FALSE;
398 xrefpos = GetDirectInteger(pDict.get(), "Prev");
395 399
396 newxrefpos = GetDirectInteger(pDict.get(), "Prev");
397 if (newxrefpos == xrefpos)
398 return FALSE;
399
400 xrefpos = newxrefpos;
401 XRefStreamList.InsertAt(0, pDict->GetInteger("XRefStm")); 400 XRefStreamList.InsertAt(0, pDict->GetInteger("XRefStm"));
402 m_Trailers.Add(pDict.release()); 401 m_Trailers.Add(pDict.release());
403 } 402 }
404 for (int32_t i = 0; i < CrossRefList.GetSize(); i++) { 403 for (int32_t i = 0; i < CrossRefList.GetSize(); i++) {
405 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) 404 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE))
406 return FALSE; 405 return FALSE;
407 } 406 }
408 return TRUE; 407 return TRUE;
409 } 408 }
410 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, 409 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos,
411 FX_DWORD dwObjCount) { 410 FX_DWORD dwObjCount) {
412 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) { 411 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) {
413 return FALSE; 412 return FALSE;
414 } 413 }
415 m_pTrailer = LoadTrailerV4(); 414 m_pTrailer = LoadTrailerV4();
416 if (!m_pTrailer) { 415 if (!m_pTrailer) {
417 return FALSE; 416 return FALSE;
418 } 417 }
419 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); 418 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size");
420 if (xrefsize == 0) { 419 if (xrefsize == 0) {
421 return FALSE; 420 return FALSE;
422 } 421 }
423 CFX_FileSizeArray CrossRefList, XRefStreamList; 422 CFX_FileSizeArray CrossRefList, XRefStreamList;
424 CrossRefList.Add(xrefpos); 423 CrossRefList.Add(xrefpos);
425 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm")); 424 XRefStreamList.Add(GetDirectInteger(m_pTrailer, "XRefStm"));
425
426 std::set<FX_FILESIZE> seen_xrefpos;
427 seen_xrefpos.insert(xrefpos);
426 xrefpos = GetDirectInteger(m_pTrailer, "Prev"); 428 xrefpos = GetDirectInteger(m_pTrailer, "Prev");
427 while (xrefpos) { 429 while (xrefpos) {
430 // Check for circular references.
431 if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end())
Lei Zhang 2016/01/05 03:30:27 Ditto.
Wei Li 2016/01/05 19:52:00 Done.
432 return FALSE;
433 seen_xrefpos.insert(xrefpos);
428 CrossRefList.InsertAt(0, xrefpos); 434 CrossRefList.InsertAt(0, xrefpos);
429 LoadCrossRefV4(xrefpos, 0, TRUE); 435 LoadCrossRefV4(xrefpos, 0, TRUE);
430 CPDF_Dictionary* pDict = LoadTrailerV4(); 436 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict(
437 LoadTrailerV4());
431 if (!pDict) { 438 if (!pDict) {
432 return FALSE; 439 return FALSE;
433 } 440 }
434 xrefpos = GetDirectInteger(pDict, "Prev"); 441 if (!CheckDirectType(pDict.get(), "Prev", PDFOBJ_NUMBER))
Lei Zhang 2016/01/05 03:30:27 Can you just see if GetDirectInteger() returns 0 i
Wei Li 2016/01/05 19:52:00 Yes, GetDirectInteger() will return 0. The loading
442 return FALSE;
443 xrefpos = GetDirectInteger(pDict.get(), "Prev");
444
435 XRefStreamList.InsertAt(0, pDict->GetInteger("XRefStm")); 445 XRefStreamList.InsertAt(0, pDict->GetInteger("XRefStm"));
436 m_Trailers.Add(pDict); 446 m_Trailers.Add(pDict.release());
437 } 447 }
438 for (int32_t i = 1; i < CrossRefList.GetSize(); i++) 448 for (int32_t i = 1; i < CrossRefList.GetSize(); i++)
439 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) { 449 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE)) {
440 return FALSE; 450 return FALSE;
441 } 451 }
442 return TRUE; 452 return TRUE;
443 } 453 }
444 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, 454 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos,
445 FX_DWORD dwObjCount) { 455 FX_DWORD dwObjCount) {
446 FX_FILESIZE dwStartPos = pos - m_Syntax.m_HeaderOffset; 456 FX_FILESIZE dwStartPos = pos - m_Syntax.m_HeaderOffset;
(...skipping 4540 matching lines...) Expand 10 before | Expand all | Expand 10 after
4987 if (!m_pLinearizedDict) 4997 if (!m_pLinearizedDict)
4988 return -1; 4998 return -1;
4989 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); 4999 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H");
4990 if (!pRange) 5000 if (!pRange)
4991 return -1; 5001 return -1;
4992 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 5002 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
4993 if (!pStreamLen) 5003 if (!pStreamLen)
4994 return -1; 5004 return -1;
4995 return pStreamLen->GetInteger(); 5005 return pStreamLen->GetInteger();
4996 } 5006 }
OLDNEW
« no previous file with comments | « no previous file | fpdfsdk/src/fpdfview_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698