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

Unified Diff: core/fpdfapi/parser/cpdf_document.cpp

Issue 2636403003: Bad indexing in CPDF_Document::FindPageIndex when page tree corrupt. (Closed)
Patch Set: return -1 for out-of-range Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfapi/parser/cpdf_document.h ('k') | fpdfsdk/fpdfdoc_embeddertest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/parser/cpdf_document.cpp
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 9e60aaa8824ca574b35a1eb459bc8ec214ba7f2d..e425cfc3282be2db8a0e63ff27b6b47654b1e1cb 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -516,18 +516,18 @@ void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) {
}
int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode,
- uint32_t& skip_count,
+ uint32_t* skip_count,
uint32_t objnum,
- int& index,
+ int* index,
int level) {
if (!pNode->KeyExist("Kids")) {
if (objnum == pNode->GetObjNum())
- return index;
+ return *index;
- if (skip_count)
- skip_count--;
+ if (*skip_count)
+ (*skip_count)--;
- index++;
+ (*index)++;
return -1;
}
@@ -539,20 +539,17 @@ int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode,
return -1;
size_t count = pNode->GetIntegerFor("Count");
- if (count <= skip_count) {
- skip_count -= count;
- index += count;
+ if (count <= *skip_count) {
+ (*skip_count) -= count;
+ (*index) += count;
return -1;
}
if (count && count == pKidList->GetCount()) {
for (size_t i = 0; i < count; i++) {
- if (CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i))) {
- if (pKid->GetRefObjNum() == objnum) {
- m_PageList[index + i] = objnum;
Tom Sepez 2017/01/18 18:08:42 Note: move to 592 and sanity checked.
- return static_cast<int>(index + i);
- }
- }
+ CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i));
+ if (pKid && pKid->GetRefObjNum() == objnum)
+ return static_cast<int>(*index + i);
}
}
@@ -585,8 +582,15 @@ int CPDF_Document::GetPageIndex(uint32_t objnum) {
if (!pPages)
return -1;
- int index = 0;
- return FindPageIndex(pPages, skip_count, objnum, index);
+ int start_index = 0;
+ int found_index = FindPageIndex(pPages, &skip_count, objnum, &start_index);
+
+ // Corrupt page tree may yield out-of-range results.
+ if (found_index < 0 || found_index >= pdfium::CollectionSize<int>(m_PageList))
+ return -1;
+
+ m_PageList[found_index] = objnum;
+ return found_index;
}
int CPDF_Document::GetPageCount() const {
« no previous file with comments | « core/fpdfapi/parser/cpdf_document.h ('k') | fpdfsdk/fpdfdoc_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698