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

Unified Diff: pdf/pdfium/pdfium_engine.cc

Issue 2414323003: Validate page index in PDFiumEngine::ScrollToPage(). (Closed)
Patch Set: Created 4 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 | « pdf/pdfium/pdfium_engine.h ('k') | 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 dad493a338182dca1de05cf07f4481353fee0feb..80b7d2d818b279f4f95c6f2af131d939d048ee7f 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -2341,17 +2341,17 @@ void PDFiumEngine::OnCallback(int id) {
}
int PDFiumEngine::GetCharCount(int page_index) {
- DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size()));
+ DCHECK(PageIndexInBounds(page_index));
return pages_[page_index]->GetCharCount();
}
pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) {
- DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size()));
+ DCHECK(PageIndexInBounds(page_index));
return pages_[page_index]->GetCharBounds(char_index);
}
uint32_t PDFiumEngine::GetCharUnicode(int page_index, int char_index) {
- DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size()));
+ DCHECK(PageIndexInBounds(page_index));
return pages_[page_index]->GetCharUnicode(char_index);
}
@@ -2360,7 +2360,7 @@ void PDFiumEngine::GetTextRunInfo(int page_index,
uint32_t* out_len,
double* out_font_size,
pp::FloatRect* out_bounds) {
- DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size()));
+ DCHECK(PageIndexInBounds(page_index));
return pages_[page_index]->GetTextRunInfo(start_char_index, out_len,
out_font_size, out_bounds);
}
@@ -2701,6 +2701,9 @@ bool PDFiumEngine::IsPageVisible(int index) const {
}
void PDFiumEngine::ScrollToPage(int page) {
+ if (!PageIndexInBounds(page))
+ return;
+
in_flight_visible_page_ = page;
client_->ScrollToPage(page);
}
@@ -2771,8 +2774,7 @@ bool PDFiumEngine::ContinuePaint(int progressive_index,
int rv;
FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap;
int page_index = progressive_paints_[progressive_index].page_index;
- DCHECK_GE(page_index, 0);
- DCHECK_LT(static_cast<size_t>(page_index), pages_.size());
+ DCHECK(PageIndexInBounds(page_index));
FPDF_PAGE page = pages_[page_index]->GetPage();
last_progressive_start_time_ = base::Time::Now();
@@ -3424,6 +3426,10 @@ void PDFiumEngine::SetSelecting(bool selecting) {
client_->IsSelectingChanged(selecting);
}
+bool PDFiumEngine::PageIndexInBounds(int index) const {
+ return index >= 0 && index < static_cast<int>(pages_.size());
+}
+
void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param,
FPDF_PAGE page,
double left,
@@ -3507,14 +3513,13 @@ FPDF_PAGE PDFiumEngine::Form_GetPage(FPDF_FORMFILLINFO* param,
FPDF_DOCUMENT document,
int page_index) {
PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- if (page_index < 0 || page_index >= static_cast<int>(engine->pages_.size()))
+ if (!engine->PageIndexInBounds(page_index))
return nullptr;
return engine->pages_[page_index]->GetPage();
}
FPDF_PAGE PDFiumEngine::Form_GetCurrentPage(FPDF_FORMFILLINFO* param,
FPDF_DOCUMENT document) {
- // TODO(jam): find out what this is used for.
PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
int index = engine->last_page_mouse_down_;
if (index == -1) {
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698