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

Unified Diff: pdf/pdfium/pdfium_engine.cc

Issue 1401263005: Stack exhaustion if PDFium returns circular bookmarks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/pdfium/pdfium_engine.cc
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc
index 369aa206b3d54ee0eec04ad5df5c28d84f2d786b..a7cfcd9085fc309ea068946998300a91b0bec0be 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -544,7 +544,9 @@ void FormatStringForOS(base::string16* text) {
// child VarDictionaries (representing the child bookmarks).
// If NULL is passed in as the bookmark then we traverse from the "root".
// Note that the "root" bookmark contains no useful information.
-pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc, FPDF_BOOKMARK bookmark) {
+pp::VarDictionary TraverseBookmarks(unsigned int depth,
Lei Zhang 2015/10/13 20:07:56 nit: Can depth be the last param?
+ FPDF_DOCUMENT doc,
+ FPDF_BOOKMARK bookmark) {
pp::VarDictionary dict;
base::string16 title;
unsigned long buffer_size = FPDFBookmark_GetTitle(bookmark, NULL, 0);
@@ -564,12 +566,19 @@ pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc, FPDF_BOOKMARK bookmark) {
}
pp::VarArray children;
- int child_index = 0;
- for (FPDF_BOOKMARK child_bookmark = FPDFBookmark_GetFirstChild(doc, bookmark);
- child_bookmark != NULL;
- child_bookmark = FPDFBookmark_GetNextSibling(doc, child_bookmark)) {
- children.Set(child_index, TraverseBookmarks(doc, child_bookmark));
- child_index++;
+
+ // Don't trust PDFium to handle circular bookmarks.
+ const unsigned int kMaxDepth = 128;
Lei Zhang 2015/10/13 20:07:56 How did we pick 128?
+ if (depth < kMaxDepth) {
+ int child_index = 0;
+ for (FPDF_BOOKMARK child_bookmark =
+ FPDFBookmark_GetFirstChild(doc, bookmark);
+ child_bookmark != NULL;
+ child_bookmark = FPDFBookmark_GetNextSibling(doc, child_bookmark)) {
+ children.Set(child_index,
+ TraverseBookmarks(depth + 1, doc, child_bookmark));
+ child_index++;
+ }
}
dict.Set(pp::Var("children"), children);
return dict;
@@ -2433,7 +2442,7 @@ int PDFiumEngine::GetNumberOfPages() {
}
pp::VarArray PDFiumEngine::GetBookmarks() {
- pp::VarDictionary dict = TraverseBookmarks(doc_, NULL);
+ pp::VarDictionary dict = TraverseBookmarks(0, doc_, NULL);
// The root bookmark contains no useful information.
return pp::VarArray(dict.Get(pp::Var("children")));
}
« 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