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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | pdf/pdfium/pdfium_page.cc » ('j') | pdf/pdfium/pdfium_page.cc » ('J')
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 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 int text_length = pages_[current_page]->GetCharCount(); 2043 int text_length = pages_[current_page]->GetCharCount();
2044 if (character_to_start_searching_from) { 2044 if (character_to_start_searching_from) {
2045 text_length -= character_to_start_searching_from; 2045 text_length -= character_to_start_searching_from;
2046 } else if (!first_search && 2046 } else if (!first_search &&
2047 last_character_index_to_search_ != -1 && 2047 last_character_index_to_search_ != -1 &&
2048 current_page == last_page_to_search_) { 2048 current_page == last_page_to_search_) {
2049 text_length = last_character_index_to_search_; 2049 text_length = last_character_index_to_search_;
2050 } 2050 }
2051 if (text_length <= 0) 2051 if (text_length <= 0)
2052 return; 2052 return;
2053
2053 unsigned short* data = 2054 unsigned short* data =
2054 reinterpret_cast<unsigned short*>(WriteInto(&page_text, text_length + 1)); 2055 reinterpret_cast<unsigned short*>(WriteInto(&page_text, text_length + 1));
2055 FPDFText_GetText(pages_[current_page]->GetTextPage(), 2056 // |written| includes the trailing terminator, so get rid of the trailing
2056 character_to_start_searching_from, 2057 // NUL character by calling resize().
2057 text_length, 2058 int written = FPDFText_GetText(pages_[current_page]->GetTextPage(),
2058 data); 2059 character_to_start_searching_from,
2060 text_length,
2061 data);
2062 if (written < 1)
2063 page_text.resize(0);
2064 else
2065 page_text.resize(written - 1);
2066
2059 std::vector<PDFEngine::Client::SearchStringResult> results; 2067 std::vector<PDFEngine::Client::SearchStringResult> results;
2060 client_->SearchString( 2068 client_->SearchString(
2061 page_text.c_str(), term.c_str(), case_sensitive, &results); 2069 page_text.c_str(), term.c_str(), case_sensitive, &results);
2062 for (size_t i = 0; i < results.size(); ++i) { 2070 for (size_t i = 0; i < results.size(); ++i) {
2063 // Need to map the indexes from the page text, which may have generated 2071 // Need to map the indexes from the page text, which may have generated
2064 // characters like space etc, to character indices from the page. 2072 // characters like space etc, to character indices from the page.
2065 int temp_start = results[i].start_index + character_to_start_searching_from; 2073 int temp_start = results[i].start_index + character_to_start_searching_from;
2066 int start = FPDFText_GetCharIndexFromTextIndex( 2074 int start = FPDFText_GetCharIndexFromTextIndex(
2067 pages_[current_page]->GetTextPage(), temp_start); 2075 pages_[current_page]->GetTextPage(), temp_start);
2068 int end = FPDFText_GetCharIndexFromTextIndex( 2076 int end = FPDFText_GetCharIndexFromTextIndex(
(...skipping 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after
3881 double* height) { 3889 double* height) {
3882 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3890 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
3883 if (!doc) 3891 if (!doc)
3884 return false; 3892 return false;
3885 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3893 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3886 FPDF_CloseDocument(doc); 3894 FPDF_CloseDocument(doc);
3887 return success; 3895 return success;
3888 } 3896 }
3889 3897
3890 } // namespace chrome_pdf 3898 } // namespace chrome_pdf
OLDNEW
« 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