summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdftext.cpp
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-09-05 11:48:55 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-05 16:20:37 +0000
commit2bf05a6ca144e78223795ae1716875d3c9b8acb1 (patch)
tree2a851799ac9cfac5b283a1284ddf96215da6602d /fpdfsdk/fpdftext.cpp
parent1c9ad7ec7353cccabb6881fd22b116daa3dcbb84 (diff)
downloadpdfium-2bf05a6ca144e78223795ae1716875d3c9b8acb1.tar.xz
Leave space for null characters when getting text
The conversion from WideString to ByeString adds in null characters at the end, so we need to account for these when selecting the range of text to initially extract. BUG=chromium:761770,chromium:761626 Change-Id: Ib8f863e997ebccaaf882e0beb29733f27a18826d Reviewed-on: https://pdfium-review.googlesource.com/13110 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdftext.cpp')
-rw-r--r--fpdfsdk/fpdftext.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp
index 6df593f710..6a030b8ebd 100644
--- a/fpdfsdk/fpdftext.cpp
+++ b/fpdfsdk/fpdftext.cpp
@@ -29,6 +29,8 @@
namespace {
+constexpr size_t kBytesPerCharacter = sizeof(unsigned short);
+
CPDF_TextPage* CPDFTextPageFromFPDFTextPage(FPDF_TEXTPAGE text_page) {
return static_cast<CPDF_TextPage*>(text_page);
}
@@ -169,19 +171,19 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetText(FPDF_TEXTPAGE text_page,
if (start >= textpage->CountChars())
return 0;
- CFX_WideString str = textpage->GetPageText(start, count);
+ CFX_WideString str = textpage->GetPageText(start, count - 1);
if (str.GetLength() <= 0)
return 0;
// UFT16LE_Encode doesn't handle surrogate pairs properly, so it is expected
// the number of items to stay the same.
CFX_ByteString cbUTF16str = str.UTF16LE_Encode();
- ASSERT(cbUTF16str.GetLength() / sizeof(unsigned short) <=
+ ASSERT(cbUTF16str.GetLength() / kBytesPerCharacter <=
static_cast<size_t>(count));
memcpy(result, cbUTF16str.GetBuffer(cbUTF16str.GetLength()),
cbUTF16str.GetLength());
- return cbUTF16str.GetLength() / sizeof(unsigned short);
+ return cbUTF16str.GetLength() / kBytesPerCharacter;
}
FPDF_EXPORT int FPDF_CALLCONV FPDFText_CountRects(FPDF_TEXTPAGE text_page,