Skip to content

Bad alignment in convertUTF16ToUTF8String #18856

Open
@stoklund

Description

@stoklund
Bugzilla Link 18482
Version trunk
OS All
CC @rnk

Extended Description

lib/Support/ConvertUTFWrapper.cpp contains this code:

bool convertUTF16ToUTF8String(ArrayRef SrcBytes, std::string &Out) {
...
const UTF16 *Src = reinterpret_cast<const UTF16 *>(SrcBytes.begin());
const UTF16 *SrcEnd = reinterpret_cast<const UTF16 *>(SrcBytes.end());
...
if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {

The UTF16 type is normally 2-byte aligned, and there is no guarantee that the ArrayRef points to aligned bytes.

This crashes the unit test ConvertUTFTest.ConvertUTF16LittleEndianToUTF8String on SPARC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions