Merge pull request #262 from ibanic/master
Prevent accessing empty buffer when using FilteredOutputStream with ICU
This commit is contained in:
commit
edcb4b4b1f
@ -433,6 +433,9 @@ void charsetFilteredOutputStream_icu::writeImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const size_t uniLength = uniTarget - &uniBuffer[0];
|
const size_t uniLength = uniTarget - &uniBuffer[0];
|
||||||
|
if(uniLength == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Allocate buffer for destination charset
|
// Allocate buffer for destination charset
|
||||||
const size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength;
|
const size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength;
|
||||||
@ -520,6 +523,9 @@ void charsetFilteredOutputStream_icu::flush() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const size_t uniLength = uniTarget - &uniBuffer[0];
|
const size_t uniLength = uniTarget - &uniBuffer[0];
|
||||||
|
if(uniLength == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Allocate buffer for destination charset
|
// Allocate buffer for destination charset
|
||||||
const size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength;
|
const size_t cpSize = ucnv_getMinCharSize(m_to) * uniLength;
|
||||||
|
@ -34,6 +34,7 @@ VMIME_TEST_SUITE_BEGIN(charsetTest)
|
|||||||
// Test valid input
|
// Test valid input
|
||||||
VMIME_TEST(testConvertStringValid)
|
VMIME_TEST(testConvertStringValid)
|
||||||
VMIME_TEST(testConvertStreamValid)
|
VMIME_TEST(testConvertStreamValid)
|
||||||
|
VMIME_TEST(testConvertStreamExtract)
|
||||||
VMIME_TEST(testEncodingHebrew1255)
|
VMIME_TEST(testEncodingHebrew1255)
|
||||||
|
|
||||||
// IDNA
|
// IDNA
|
||||||
@ -104,6 +105,32 @@ VMIME_TEST_SUITE_BEGIN(charsetTest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testConvertStreamExtract() {
|
||||||
|
vmime::bodyPart p;
|
||||||
|
p.getBody()->setContents(
|
||||||
|
vmime::make_shared <vmime::stringContentHandler>(
|
||||||
|
"Foo éé\r\né bar\r\nbaz"
|
||||||
|
),
|
||||||
|
vmime::mediaType("text", "plain"),
|
||||||
|
vmime::charset("utf-8"),
|
||||||
|
vmime::encoding("quoted-printable")
|
||||||
|
);
|
||||||
|
|
||||||
|
vmime::string str;
|
||||||
|
vmime::utility::outputStreamStringAdapter outStr(str);
|
||||||
|
vmime::shared_ptr <vmime::charsetConverter> conv = vmime::charsetConverter::create(p.getBody()->getCharset(), vmime::charset("US-ASCII"));
|
||||||
|
auto filteredStream = conv->getFilteredOutputStream(outStr);
|
||||||
|
p.getBody()->getContents()->extract(*filteredStream);
|
||||||
|
filteredStream->flush();
|
||||||
|
VASSERT_EQ(
|
||||||
|
"generate",
|
||||||
|
"Foo ??\r\n"
|
||||||
|
"? bar\r\n"
|
||||||
|
"baz",
|
||||||
|
str
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void testEncodingHebrew1255() {
|
void testEncodingHebrew1255() {
|
||||||
|
|
||||||
// hewbrew string in windows-1255 charset
|
// hewbrew string in windows-1255 charset
|
||||||
|
Loading…
x
Reference in New Issue
Block a user