From 3221f30da9311472d28f67a2a1af43cabdde71ea Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 22 Jul 2016 12:59:13 +0100 Subject: crashtesting: fix tdf92993-1.docx failure Change-Id: I76f09a09fd6c3b114ba74737d4a1ba5dad0fd28f (cherry picked from commit 5e46e382694587e88ecdebc7fa57e90fbaca7a76) Reviewed-on: https://gerrit.libreoffice.org/27436 Tested-by: Jenkins Reviewed-by: Miklos Vajna (cherry picked from commit e213a7cfe79f594065b6d64114749c5f49f2380c) --- i18npool/qa/cppunit/test_breakiterator.cxx | 16 ++++++++++++++++ i18npool/source/breakiterator/breakiterator_unicode.cxx | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/i18npool/qa/cppunit/test_breakiterator.cxx b/i18npool/qa/cppunit/test_breakiterator.cxx index 29fc48909d12..1c8b1f9a7ac5 100644 --- a/i18npool/qa/cppunit/test_breakiterator.cxx +++ b/i18npool/qa/cppunit/test_breakiterator.cxx @@ -142,6 +142,22 @@ void TestBreakIterator::testLineBreaking() CPPUNIT_ASSERT_MESSAGE("Expected a break at the start of the line, not at ]", aResult.breakIndex == 0); } } + + //this is an example sequence from tdf92993-1.docx caught by the load crashtesting + { + const sal_Unicode WEIRD1[] = { 0xd83c, 0xdf56, 0xd83c, 0xdf57, 0xd83c, 0xdf46, + 0xd83c, 0xdf64, 0x2668, 0xfe0f, 0xd83c, 0xdfc6}; + + OUString aTest(WEIRD1, SAL_N_ELEMENTS(WEIRD1)); + + aLocale.Language = "en"; + aLocale.Country = "US"; + + { + //This must not assert/crash + (void)m_xBreak->getLineBreak(aTest, 0, aLocale, 0, aHyphOptions, aUserOptions); + } + } } //See https://bugs.libreoffice.org/show_bug.cgi?id=49629 diff --git a/i18npool/source/breakiterator/breakiterator_unicode.cxx b/i18npool/source/breakiterator/breakiterator_unicode.cxx index 9fba6a3f05ec..a55149152daa 100644 --- a/i18npool/source/breakiterator/breakiterator_unicode.cxx +++ b/i18npool/source/breakiterator/breakiterator_unicode.cxx @@ -423,7 +423,7 @@ LineBreakResults SAL_CALL BreakIterator_Unicode::getLineBreak( GlueSpace=false; if (lbr.breakType == BreakType::WORDBOUNDARY) { nStartPos = lbr.breakIndex; - if (Text[nStartPos--] == WJ) + if (nStartPos >= 0 && Text[nStartPos--] == WJ) GlueSpace=true; while (nStartPos >= 0 && (u_isWhitespace(Text.iterateCodePoints(&nStartPos, 0)) || Text[nStartPos] == WJ)) { -- cgit