closes https://github.com/assimp/assimp/issues/1459: fix out-of-boundary access error

pull/1468/head
Kim Kulling 2017-09-29 21:58:58 +02:00
parent b1410f8455
commit c42589460d
2 changed files with 25 additions and 36 deletions

View File

@ -176,36 +176,29 @@ static void UnknownChunk(StreamReaderLE* stream, const SIBChunk& chunk)
}
// Reads a UTF-16LE string and returns it at UTF-8.
static aiString ReadString(StreamReaderLE* stream, uint32_t numWChars)
{
if ( 0 == numWChars ) {
static aiString ReadString(StreamReaderLE *stream, uint32_t numWChars) {
if ( nullptr == stream || 0 == numWChars ) {
static const aiString empty;
return empty;
}
// Allocate buffers (max expansion is 1 byte -> 4 bytes for UTF-8)
//UTF16* temp = new UTF16[numWChars];
std::vector<unsigned char> str;
str.reserve(numWChars * 4 + 1);
//unsigned char* str = new unsigned char[numWChars * 4 + 1];
uint16_t *temp = new uint16_t[numWChars];
for (uint32_t n=0;n<numWChars;n++)
temp[n] = stream->GetU2();
str.reserve( numWChars * 4 + 1 );
uint16_t *temp = new uint16_t[ numWChars ];
for ( uint32_t n = 0; n < numWChars; ++n ) {
temp[ n ] = stream->GetU2();
}
// Convert it and NUL-terminate.
//const UTF16 *start = temp, *end = temp + numWChars;
const uint16_t *start( temp ), *end( temp + numWChars );
utf8::utf16to8( start, end, back_inserter( str ) );
str[ str.size() - 1 ] = '\0';
const uint16_t *start = temp, *end = temp + numWChars;
utf8::utf16to8(start, end, back_inserter(str));
//UTF8 *dest = str, *limit = str + numWChars*4;
//ConvertUTF16toUTF8(&start, end, &dest, limit, lenientConversion);
//*dest = '\0';
str[str.size()] = '\0';
// Return the final string.
aiString result = aiString((const char *)&str[0]);
//delete[] str;
delete[] temp;
return result;
}
@ -223,26 +216,26 @@ SIBImporter::~SIBImporter() {
// ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file.
bool SIBImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const
{
bool SIBImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const {
return SimpleExtensionCheck(pFile, "sib");
}
// ------------------------------------------------------------------------------------------------
const aiImporterDesc* SIBImporter::GetInfo () const
{
const aiImporterDesc* SIBImporter::GetInfo () const {
return &desc;
}
// ------------------------------------------------------------------------------------------------
static void ReadVerts(SIBMesh* mesh, StreamReaderLE* stream, uint32_t count)
{
mesh->pos.resize(count);
static void ReadVerts(SIBMesh* mesh, StreamReaderLE* stream, uint32_t count) {
if ( nullptr == mesh || nullptr == stream ) {
return;
}
for (uint32_t n=0;n<count;n++) {
mesh->pos[n].x = stream->GetF4();
mesh->pos[n].y = stream->GetF4();
mesh->pos[n].z = stream->GetF4();
mesh->pos.resize(count);
for ( uint32_t n=0; n<count; ++n ) {
mesh->pos[ n ].x = stream->GetF4();
mesh->pos[ n ].y = stream->GetF4();
mesh->pos[ n ].z = stream->GetF4();
}
}

View File

@ -291,15 +291,11 @@ private:
throw DeadlyImportError("End of file or stream limit was reached");
}
///*#ifdef __arm__
T f;
::memcpy (&f, current, sizeof(T));
//#else*/
// T f = *((const T*)current);
//#endif
Intern :: Getter<SwapEndianess,T,RuntimeSwitch>() (&f,le);
Intern::Getter<SwapEndianess,T,RuntimeSwitch>() (&f,le);
current += sizeof(T);
return f;
}