Make sure no overflow can happen

- During UTF32 LE with BOM make sure that the byteswap operation will have enough space when iterating through the text buffer, which shall get encoded.
- closes https://github.com/assimp/assimp/issues/4230
pull/4282/head
Kim Kulling 2021-12-22 19:45:19 +01:00 committed by GitHub
parent 80b0b897ed
commit 2eb86d75b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -65,6 +65,7 @@ using namespace Assimp;
// Constructor to be privately used by Importer
BaseImporter::BaseImporter() AI_NO_EXCEPT
: m_progress() {
// empty
}
// ------------------------------------------------------------------------------------------------
@ -371,11 +372,16 @@ void BaseImporter::ConvertToUTF8(std::vector<char> &data) {
}
// UTF 16 BE with BOM
size_t index = 0;
if (*((uint16_t *)&data.front()) == 0xFFFE) {
// swap the endianness ..
for (uint16_t *p = (uint16_t *)&data.front(), *end = (uint16_t *)&data.back(); p <= end; ++p) {
ByteSwap::Swap2(p);
// Check to ensure no overflow can happen
if ((index+2) < data.Size()) {
// Swap the data
ByteSwap::Swap2(p);
index += 2;
}
}
}