summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-09-03 15:50:09 +0200
committerStephan Bergmann <sbergman@redhat.com>2019-09-03 20:18:28 +0200
commit238f6f42b381198e14f6d17649d8465425c7450f (patch)
tree7d3eeb9d542a9274875adac1a6f39d7f259890a7 /sal
parent91a97c5e0b7b760ec0b46ad38b28ec1419c7d48f (diff)
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@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/qa/rtl/textenc/rtl_textcvt.cxx21
-rw-r--r--sal/textenc/tcvtutf7.cxx17
2 files changed, 31 insertions, 7 deletions
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++;
}
}