[Libreoffice-commits] core.git: sal/qa sal/textenc
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Tue Sep 3 18:19:20 UTC 2019
sal/qa/rtl/textenc/rtl_textcvt.cxx | 21 +++++++++++++++++++++
sal/textenc/tcvtutf7.cxx | 17 ++++++++++-------
2 files changed, 31 insertions(+), 7 deletions(-)
New commits:
commit 238f6f42b381198e14f6d17649d8465425c7450f
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Sep 3 15:50:09 2019 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Sep 3 20:18:28 2019 +0200
Fix handling of invalid bytes >= 0x80 in ImplUTF7ToUnicode
Change-Id: I08838f9ae34a31712d7269ddaaee3fe59ece2178
Reviewed-on: https://gerrit.libreoffice.org/78562
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/sal/qa/rtl/textenc/rtl_textcvt.cxx b/sal/qa/rtl/textenc/rtl_textcvt.cxx
index 339075decba3..6b5a7e55fe21 100644
--- a/sal/qa/rtl/textenc/rtl_textcvt.cxx
+++ b/sal/qa/rtl/textenc/rtl_textcvt.cxx
@@ -453,6 +453,8 @@ public:
void testComplexCut();
+ void testInvalidUtf7();
+
void testInvalidUtf8();
void testSRCBUFFERTOSMALL();
@@ -467,6 +469,7 @@ public:
CPPUNIT_TEST(testSingleByte);
CPPUNIT_TEST(testComplex);
CPPUNIT_TEST(testComplexCut);
+ CPPUNIT_TEST(testInvalidUtf7);
CPPUNIT_TEST(testInvalidUtf8);
CPPUNIT_TEST(testSRCBUFFERTOSMALL);
CPPUNIT_TEST(testMime);
@@ -2638,6 +2641,24 @@ void Test::testComplexCut() {
#endif
}
+void Test::testInvalidUtf7() {
+ auto const converter = rtl_createTextToUnicodeConverter(RTL_TEXTENCODING_UTF7);
+ CPPUNIT_ASSERT(converter != nullptr);
+ sal_Unicode buf[TEST_STRING_SIZE];
+ sal_uInt32 info;
+ sal_Size converted;
+ auto const size = rtl_convertTextToUnicode(
+ converter, nullptr, RTL_CONSTASCII_STRINGPARAM("\x80"), buf, TEST_STRING_SIZE,
+ (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
+ | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT | RTL_TEXTTOUNICODE_FLAGS_FLUSH),
+ &info, &converted);
+ CPPUNIT_ASSERT_EQUAL(sal_Size(1), size);
+ CPPUNIT_ASSERT_EQUAL(OUString(u"\uFFFD"), OUString(buf, sal_Int32(size)));
+ CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_INVALID, info);
+ CPPUNIT_ASSERT_EQUAL(sal_Size(1), converted);
+ rtl_destroyTextToUnicodeConverter(converter);
+}
+
void Test::testInvalidUtf8() {
// UTF-8, invalid bytes:
{
diff --git a/sal/textenc/tcvtutf7.cxx b/sal/textenc/tcvtutf7.cxx
index 46c135859566..dd97b213750b 100644
--- a/sal/textenc/tcvtutf7.cxx
+++ b/sal/textenc/tcvtutf7.cxx
@@ -358,15 +358,18 @@ sal_Size ImplUTF7ToUnicode( SAL_UNUSED_PARAMETER const void*, void* pContext,
= RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
}
}
-
- /* Write char to unicode buffer */
- if ( pDestBuf >= pEndDestBuf )
+ else
{
- *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOOSMALL;
- break;
+ /* Write char to unicode buffer */
+ if ( pDestBuf >= pEndDestBuf )
+ {
+ *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOOSMALL;
+ break;
+ }
+ *pDestBuf = c;
+ pDestBuf++;
+
}
- *pDestBuf = c;
- pDestBuf++;
}
}
More information about the Libreoffice-commits
mailing list