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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 1559703002: PDF: Fix another case of circular references with bookmarks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.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 | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 #include "pdf/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <set>
12
11 #include "base/i18n/icu_encoding_detection.h" 13 #include "base/i18n/icu_encoding_detection.h"
12 #include "base/i18n/icu_string_conversions.h" 14 #include "base/i18n/icu_string_conversions.h"
13 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
14 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
15 #include "base/logging.h" 17 #include "base/logging.h"
16 #include "base/macros.h" 18 #include "base/macros.h"
17 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
18 #include "base/numerics/safe_conversions.h" 20 #include "base/numerics/safe_conversions.h"
19 #include "base/stl_util.h" 21 #include "base/stl_util.h"
20 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 int page_index = FPDFDest_GetPageIndex(doc, dest); 428 int page_index = FPDFDest_GetPageIndex(doc, dest);
427 dict.Set(pp::Var("page"), pp::Var(page_index)); 429 dict.Set(pp::Var("page"), pp::Var(page_index));
428 } 430 }
429 431
430 pp::VarArray children; 432 pp::VarArray children;
431 433
432 // Don't trust PDFium to handle circular bookmarks. 434 // Don't trust PDFium to handle circular bookmarks.
433 const unsigned int kMaxDepth = 128; 435 const unsigned int kMaxDepth = 128;
434 if (depth < kMaxDepth) { 436 if (depth < kMaxDepth) {
435 int child_index = 0; 437 int child_index = 0;
438 std::set<FPDF_BOOKMARK> seen_bookmarks;
436 for (FPDF_BOOKMARK child_bookmark = 439 for (FPDF_BOOKMARK child_bookmark =
437 FPDFBookmark_GetFirstChild(doc, bookmark); 440 FPDFBookmark_GetFirstChild(doc, bookmark);
438 child_bookmark != NULL; 441 child_bookmark != nullptr;
Tom Sepez 2016/01/04 18:59:22 nit: just child_bookmark;
Lei Zhang 2016/01/04 21:44:43 Done.
439 child_bookmark = FPDFBookmark_GetNextSibling(doc, child_bookmark)) { 442 child_bookmark = FPDFBookmark_GetNextSibling(doc, child_bookmark)) {
443 if (ContainsKey(seen_bookmarks, child_bookmark))
444 break;
445
446 seen_bookmarks.insert(child_bookmark);
440 children.Set(child_index, 447 children.Set(child_index,
441 TraverseBookmarks(doc, child_bookmark, depth + 1)); 448 TraverseBookmarks(doc, child_bookmark, depth + 1));
442 child_index++; 449 child_index++;
443 } 450 }
444 } 451 }
445 dict.Set(pp::Var("children"), children); 452 dict.Set(pp::Var("children"), children);
446 return dict; 453 return dict;
447 } 454 }
448 455
449 std::string GetDocumentMetadata(FPDF_DOCUMENT doc, const std::string& key) { 456 std::string GetDocumentMetadata(FPDF_DOCUMENT doc, const std::string& key) {
(...skipping 3558 matching lines...) Expand 10 before | Expand all | Expand 10 after
4008 double* height) { 4015 double* height) {
4009 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 4016 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
4010 if (!doc) 4017 if (!doc)
4011 return false; 4018 return false;
4012 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4019 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4013 FPDF_CloseDocument(doc); 4020 FPDF_CloseDocument(doc);
4014 return success; 4021 return success;
4015 } 4022 }
4016 4023
4017 } // namespace chrome_pdf 4024 } // namespace chrome_pdf
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