summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-12-09 23:56:51 -0800
committerLei Zhang <thestig@chromium.org>2015-12-09 23:56:51 -0800
commit5fae972302efd368a3ecc7cfa655891323c59a1b (patch)
treed77db9b3ecb77b129cc05ba69bbd7b74e7c7f0f2 /core/src/fpdfapi
parent3b1707f50e4961c2a350243acbeaaafd89e22fca (diff)
downloadpdfium-5fae972302efd368a3ecc7cfa655891323c59a1b.tar.xz
Merge to XFA: Prevent infinite looping in CPDF_Parser::LoadAllCrossRefV5().
BUG=pdfium:298 TBR=weili@chromium.org Review URL: https://codereview.chromium.org/1496703005 . (cherry picked from commit 93181f9a20db7ac706bb9405750303db93762a5b) Review URL: https://codereview.chromium.org/1514783002 .
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp39
1 files changed, 26 insertions, 13 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index f64ba0deb0..bc5d3edc2b 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -582,21 +582,29 @@ bool CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos,
}
m_Syntax.RestorePos(SavedPos + count * recordsize);
}
- return !streampos || LoadCrossRefV5(streampos, streampos, FALSE);
+ return !streampos || LoadCrossRefV5(&streampos, FALSE);
}
FX_BOOL CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) {
- if (!LoadCrossRefV5(xrefpos, xrefpos, TRUE)) {
+ if (!LoadCrossRefV5(&xrefpos, TRUE)) {
return FALSE;
}
- while (xrefpos)
- if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) {
+ std::set<FX_FILESIZE> seen_xrefpos;
+ while (xrefpos) {
+ seen_xrefpos.insert(xrefpos);
+ if (!LoadCrossRefV5(&xrefpos, FALSE)) {
+ return FALSE;
+ }
+ // Check for circular references.
+ if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) {
return FALSE;
}
+ }
m_ObjectStreamMap.InitHashTable(101, FALSE);
m_bXRefStream = TRUE;
return TRUE;
}
+
FX_BOOL CPDF_Parser::RebuildCrossRef() {
m_CrossRef.RemoveAll();
m_V5Type.RemoveAll();
@@ -975,10 +983,8 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
return m_pTrailer && m_CrossRef.GetSize() > 0;
}
-FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos,
- FX_FILESIZE& prev,
- FX_BOOL bMainXRef) {
- CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, pos, 0, nullptr);
+FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) {
+ CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0, nullptr);
if (!pObject)
return FALSE;
@@ -997,7 +1003,7 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos,
if (!pStream)
return FALSE;
- prev = pStream->GetDict()->GetInteger(FX_BSTRC("Prev"));
+ *pos = pStream->GetDict()->GetInteger(FX_BSTRC("Prev"));
int32_t size = pStream->GetDict()->GetInteger(FX_BSTRC("Size"));
if (size < 0) {
pStream->Release();
@@ -1563,7 +1569,7 @@ FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess,
FX_BOOL bXRefRebuilt = FALSE;
FX_BOOL bLoadV4 = FALSE;
if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE, FALSE)) &&
- !LoadCrossRefV5(dwFirstXRefOffset, dwFirstXRefOffset, TRUE)) {
+ !LoadCrossRefV5(&dwFirstXRefOffset, TRUE)) {
if (!RebuildCrossRef()) {
return PDFPARSE_ERROR_FORMAT;
}
@@ -1623,13 +1629,20 @@ FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess,
return PDFPARSE_ERROR_SUCCESS;
}
FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) {
- if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) {
+ if (!LoadCrossRefV5(&xrefpos, FALSE)) {
return FALSE;
}
- while (xrefpos)
- if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) {
+ std::set<FX_FILESIZE> seen_xrefpos;
+ while (xrefpos) {
+ seen_xrefpos.insert(xrefpos);
+ if (!LoadCrossRefV5(&xrefpos, FALSE)) {
+ return FALSE;
+ }
+ // Check for circular references.
+ if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) {
return FALSE;
}
+ }
m_ObjectStreamMap.InitHashTable(101, FALSE);
m_bXRefStream = TRUE;
return TRUE;