Skip to content

Commit

Permalink
Move some checks to PDFiumEngine::AppendPage()
Browse files Browse the repository at this point in the history
Make PDFiumEngine::AppendPage() check its input parameters, instead of
the caller. Change these DCHECKs into CHECKs, per modern coding
guidance, since they are cheap to run. This also helps to catch a rare
crash where it looks as though the impossible has happened.

Bug: 1488743
Change-Id: Ia491b20b771beebc0cd968908873228793e86698
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4903239
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1204952}
  • Loading branch information
leizleiz authored and Chromium LUCI CQ committed Oct 4, 2023
1 parent 1858874 commit bfa2b13
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 0 additions & 2 deletions pdf/pdf_view_web_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2307,9 +2307,7 @@ void PdfViewWebPlugin::PreviewDocumentLoadComplete() {
preview_document_load_state_ = DocumentLoadState::kComplete;

int dest_page_index = preview_pages_info_.front().dest_page_index;
DCHECK_GT(dest_page_index, 0);
preview_pages_info_.pop();
DCHECK(preview_engine_);
engine_->AppendPage(preview_engine_.get(), dest_page_index);

++print_preview_loaded_page_count_;
Expand Down
3 changes: 3 additions & 0 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,9 @@ std::unique_ptr<URLLoaderWrapper> PDFiumEngine::CreateURLLoader() {
}

void PDFiumEngine::AppendPage(PDFEngine* engine, int index) {
CHECK(engine);
CHECK(PageIndexInBounds(index));

// Unload and delete the blank page before appending.
pages_[index]->Unload();
pages_[index]->set_calculated_links(false);
Expand Down

0 comments on commit bfa2b13

Please sign in to comment.