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

Unified Diff: pdf/pdfium/pdfium_engine.cc

Issue 833263003: PDF: Fix extra NUL characters from incorrect WriteInto() calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comment Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pdf/pdfium/pdfium_page.cc » ('j') | pdf/pdfium/pdfium_page.cc » ('J')
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 8c49b9dc0bc67a56ed1bb3732a394ae62ec88ccb..ee6454e2d21b57a4cc6b51f709054476fbe5431d 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -2050,12 +2050,20 @@ void PDFiumEngine::SearchUsingICU(const base::string16& term,
}
if (text_length <= 0)
return;
+
unsigned short* data =
reinterpret_cast<unsigned short*>(WriteInto(&page_text, text_length + 1));
- FPDFText_GetText(pages_[current_page]->GetTextPage(),
- character_to_start_searching_from,
- text_length,
- data);
+ // |written| includes the trailing terminator, so get rid of the trailing
+ // NUL character by calling resize().
+ int written = FPDFText_GetText(pages_[current_page]->GetTextPage(),
+ character_to_start_searching_from,
+ text_length,
+ data);
+ if (written < 1)
+ page_text.resize(0);
+ else
+ page_text.resize(written - 1);
+
std::vector<PDFEngine::Client::SearchStringResult> results;
client_->SearchString(
page_text.c_str(), term.c_str(), case_sensitive, &results);
« no previous file with comments | « no previous file | pdf/pdfium/pdfium_page.cc » ('j') | pdf/pdfium/pdfium_page.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698