summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-02-28 12:48:33 -0800
committerLei Zhang <thestig@chromium.org>2017-02-28 20:49:57 +0000
commit66935d5be45783f34d94c7a8ac15daa6db411271 (patch)
tree8cf98a91793f4a8855ab3f31d4c52642a035aee2
parentd0cfb8cc152321f552a9d7c9754e9f05e3352e75 (diff)
downloadpdfium-chromium/2987.tar.xz
M57: Fix a wrong variable usage in PDF_EncodeText().chromium/2987
BUG=chromium:694147 Change-Id: I388cb1d117318edb0339f5c7ee1d2b072f0fb741 Reviewed-on: https://pdfium-review.googlesource.com/2832 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> (cherry picked from commit 37e2bd1acf843db4eef891d994390520b8fcf3fa) Change-Id: I295812cd4af287d0855a3d4626da49807ade6b50 Reviewed-on: https://pdfium-review.googlesource.com/2886 Reviewed-by: Lei Zhang <thestig@chromium.org>
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode.cpp2
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp33
2 files changed, 34 insertions, 1 deletions
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp
index 884b5c50d1..480e2c111f 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp
@@ -500,7 +500,7 @@ CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len) {
dest_buf2[1] = 0xff;
dest_buf2 += 2;
for (int j = 0; j < len; j++) {
- *dest_buf2++ = pString[i] >> 8;
+ *dest_buf2++ = pString[j] >> 8;
*dest_buf2++ = (uint8_t)pString[j];
}
result.ReleaseBuffer(encLen);
diff --git a/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp
index 83860f9146..30d30a433d 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp
@@ -76,3 +76,36 @@ TEST(fpdf_parser_decode, HexDecode) {
FX_Free(result);
}
}
+
+TEST(fpdf_parser_decode, EncodeText) {
+ struct EncodeTestData {
+ const FX_WCHAR* input;
+ const FX_CHAR* expected_output;
+ FX_STRSIZE expected_length;
+ } test_data[] = {
+ // Empty src string.
+ {L"", "", 0},
+ // ASCII text.
+ {L"the quick\tfox", "the quick\tfox", 13},
+ // Unicode text.
+ {L"\x0330\x0331", "\xFE\xFF\x03\x30\x03\x31", 6},
+ // More Unicode text.
+ {L"\x7F51\x9875\x0020\x56FE\x7247\x0020"
+ L"\x8D44\x8BAF\x66F4\x591A\x0020\x00BB",
+ "\xFE\xFF\x7F\x51\x98\x75\x00\x20\x56\xFE\x72\x47\x00"
+ "\x20\x8D\x44\x8B\xAF\x66\xF4\x59\x1A\x00\x20\x00\xBB",
+ 26},
+ };
+
+ for (size_t i = 0; i < FX_ArraySize(test_data); ++i) {
+ const auto& test_case = test_data[i];
+ CFX_ByteString output = PDF_EncodeText(test_case.input);
+ ASSERT_EQ(test_case.expected_length, output.GetLength()) << "for case "
+ << i;
+ const FX_CHAR* str_ptr = output.c_str();
+ for (FX_STRSIZE j = 0; j < test_case.expected_length; ++j) {
+ EXPECT_EQ(test_case.expected_output[j], str_ptr[j]) << "for case " << i
+ << " char " << j;
+ }
+ }
+}