summaryrefslogtreecommitdiff
path: root/core/fpdftext
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-08-11 16:20:32 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-11 21:03:14 +0000
commitddb9b7cdd19b63a81c4a094239e85f84acefaa17 (patch)
tree8657940fb10d76a96ffe996cf17d70a1c65ca6de /core/fpdftext
parentd27998f6526272a5b8732106aa9b75f724434aca (diff)
downloadpdfium-ddb9b7cdd19b63a81c4a094239e85f84acefaa17.tar.xz
Add checks of index operations on string classes
Specifically the index parameter passed in to GetAt(), SetAt() and operator[] are now being tested to be in bounds. BUG=chromium:752480, pdfium:828 Change-Id: I9e94d58c98a8eaaaae53cd0e3ffe2123ea17d8c4 Reviewed-on: https://pdfium-review.googlesource.com/10651 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdftext')
-rw-r--r--core/fpdftext/cpdf_textpage.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 8f0e376dbc..1470ad700d 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -945,9 +945,9 @@ bool CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj,
if (item.m_CharCode == static_cast<uint32_t>(-1))
continue;
CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode);
- wchar_t wChar = wstrItem.GetAt(0);
- if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode)
- wChar = (wchar_t)item.m_CharCode;
+ wchar_t wChar = !wstrItem.IsEmpty() ? wstrItem[0] : 0;
+ if (wChar == 0)
+ wChar = item.m_CharCode;
if (wChar)
str += wChar;
}
@@ -1222,9 +1222,11 @@ bool CPDF_TextPage::IsHyphen(wchar_t curChar) {
if (strCurText.IsEmpty())
strCurText = m_TextBuf.AsStringC();
FX_STRSIZE nCount = strCurText.GetLength();
+ if (nCount < 1)
+ return false;
int nIndex = nCount - 1;
wchar_t wcTmp = strCurText.GetAt(nIndex);
- while (wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0)
+ while (wcTmp == 0x20 && nIndex > 0 && nIndex <= nCount - 1)
wcTmp = strCurText.GetAt(--nIndex);
if (0x2D == wcTmp || 0xAD == wcTmp) {
if (--nIndex > 0) {
@@ -1353,6 +1355,8 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject(
}
CFX_WideString PrevStr =
m_pPreTextObj->GetFont()->UnicodeFromCharCode(PrevItem.m_CharCode);
+ if (PrevStr.IsEmpty())
+ return GenerateCharacter::None;
wchar_t preChar = PrevStr.GetAt(PrevStr.GetLength() - 1);
CFX_Matrix matrix = pObj->GetTextMatrix();
matrix.Concat(formMatrix);