0

[pdf] Check PDFiumRange::page_ in the constructor

The member should never be null, and it's leading to some crashes in the
wild when dereferenced. Check it in the constructor to catch the
violating caller.

Bug: 1279497
Change-Id: Idf653722f5fc6d44a541261efd5ca79959e57e5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3350795
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Auto-Submit: Daniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/main@{#952999}
This commit is contained in:
Daniel Hosseinian
2021-12-20 20:16:29 +00:00
committed by Chromium LUCI CQ
parent 81982abcc5
commit bde1dbf0b9
2 changed files with 4 additions and 0 deletions

@ -31,6 +31,9 @@ bool IsIgnorableCharacter(char16_t c) {
PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count)
: page_(page), char_index_(char_index), char_count_(char_count) {
// TODO(crbug.com/1279497): Demote this CHECK to a DCHECK after the violating
// caller is caught.
CHECK(page_);
#if DCHECK_IS_ON()
AdjustForBackwardsRange(char_index, char_count);
DCHECK_LE(char_count, FPDFText_CountChars(page_->GetTextPage()));

@ -49,6 +49,7 @@ class PDFiumRange {
std::u16string GetText() const;
private:
// The page containing the range. Must outlive `this`.
raw_ptr<PDFiumPage> page_;
// Index of first character.
int char_index_;