diff options
author | Lei Zhang <thestig@chromium.org> | 2016-01-11 11:48:11 -0800 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2016-01-11 11:48:11 -0800 |
commit | 401cd2dbaaa10790077de2fd70e8101b0bdd0f36 (patch) | |
tree | 39dd3b945967346334583b4e5bbe5d8ebc608c58 /fpdfsdk | |
parent | a07804a3b16c10fa2011ef56d1dacefb7d21e4f6 (diff) | |
download | pdfium-401cd2dbaaa10790077de2fd70e8101b0bdd0f36.tar.xz |
Fix an uninitalized read in FPDFText_GetFontSize().
BUG=pdfium:346
R=jun_fang@foxitsoftware.com
Review URL: https://codereview.chromium.org/1578543002 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/src/fpdftext.cpp | 8 | ||||
-rw-r--r-- | fpdfsdk/src/fpdftext_embeddertest.cpp | 28 |
2 files changed, 30 insertions, 6 deletions
diff --git a/fpdfsdk/src/fpdftext.cpp b/fpdfsdk/src/fpdftext.cpp index ed34ecdbf7..4659951c3c 100644 --- a/fpdfsdk/src/fpdftext.cpp +++ b/fpdfsdk/src/fpdftext.cpp @@ -33,6 +33,7 @@ DLLEXPORT int STDCALL FPDFText_CountChars(FPDF_TEXTPAGE text_page) { IPDF_TextPage* textpage = (IPDF_TextPage*)text_page; return textpage->CountChars(); } + DLLEXPORT unsigned int STDCALL FPDFText_GetUnicode(FPDF_TEXTPAGE text_page, int index) { if (!text_page) @@ -43,9 +44,10 @@ DLLEXPORT unsigned int STDCALL FPDFText_GetUnicode(FPDF_TEXTPAGE text_page, return 0; FPDF_CHAR_INFO charinfo; - textpage->GetCharInfo(index, charinfo); + textpage->GetCharInfo(index, &charinfo); return charinfo.m_Unicode; } + DLLEXPORT double STDCALL FPDFText_GetFontSize(FPDF_TEXTPAGE text_page, int index) { if (!text_page) @@ -56,7 +58,7 @@ DLLEXPORT double STDCALL FPDFText_GetFontSize(FPDF_TEXTPAGE text_page, return 0; FPDF_CHAR_INFO charinfo; - textpage->GetCharInfo(index, charinfo); + textpage->GetCharInfo(index, &charinfo); return charinfo.m_FontSize; } @@ -73,7 +75,7 @@ DLLEXPORT void STDCALL FPDFText_GetCharBox(FPDF_TEXTPAGE text_page, if (index < 0 || index >= textpage->CountChars()) return; FPDF_CHAR_INFO charinfo; - textpage->GetCharInfo(index, charinfo); + textpage->GetCharInfo(index, &charinfo); *left = charinfo.m_CharBox.left; *right = charinfo.m_CharBox.right; *bottom = charinfo.m_CharBox.bottom; diff --git a/fpdfsdk/src/fpdftext_embeddertest.cpp b/fpdfsdk/src/fpdftext_embeddertest.cpp index 4653db32ad..e84a96e966 100644 --- a/fpdfsdk/src/fpdftext_embeddertest.cpp +++ b/fpdfsdk/src/fpdftext_embeddertest.cpp @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "core/include/fxcrt/fx_basic.h" #include "public/fpdf_text.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" @@ -10,9 +11,9 @@ namespace { -static bool check_unsigned_shorts(const char* expected, - const unsigned short* actual, - size_t length) { +bool check_unsigned_shorts(const char* expected, + const unsigned short* actual, + size_t length) { if (length > strlen(expected) + 1) { return false; } @@ -367,3 +368,24 @@ TEST_F(FPDFTextEmbeddertest, WebLinks) { FPDFText_ClosePage(textpage); UnloadPage(page); } + +TEST_F(FPDFTextEmbeddertest, GetFontSize) { + EXPECT_TRUE(OpenDocument("hello_world.pdf")); + FPDF_PAGE page = LoadPage(0); + EXPECT_NE(nullptr, page); + + FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); + EXPECT_NE(nullptr, textpage); + + const double kExpectedFontsSizes[] = {12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 1, 1, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; + + int count = FPDFText_CountChars(textpage); + ASSERT_EQ(FX_ArraySize(kExpectedFontsSizes), count); + for (int i = 0; i < count; ++i) + EXPECT_EQ(kExpectedFontsSizes[i], FPDFText_GetFontSize(textpage, i)) << i; + + FPDFText_ClosePage(textpage); + UnloadPage(page); +} |