closes https://github.com/assimp/assimp/issues/1459: fix out-of-boundary access error
parent
b1410f8455
commit
c42589460d
|
@ -176,36 +176,29 @@ static void UnknownChunk(StreamReaderLE* stream, const SIBChunk& chunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads a UTF-16LE string and returns it at UTF-8.
|
// Reads a UTF-16LE string and returns it at UTF-8.
|
||||||
static aiString ReadString(StreamReaderLE* stream, uint32_t numWChars)
|
static aiString ReadString(StreamReaderLE *stream, uint32_t numWChars) {
|
||||||
{
|
if ( nullptr == stream || 0 == numWChars ) {
|
||||||
if ( 0 == numWChars ) {
|
|
||||||
static const aiString empty;
|
static const aiString empty;
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate buffers (max expansion is 1 byte -> 4 bytes for UTF-8)
|
// Allocate buffers (max expansion is 1 byte -> 4 bytes for UTF-8)
|
||||||
//UTF16* temp = new UTF16[numWChars];
|
|
||||||
std::vector<unsigned char> str;
|
std::vector<unsigned char> str;
|
||||||
str.reserve(numWChars * 4 + 1);
|
str.reserve( numWChars * 4 + 1 );
|
||||||
//unsigned char* str = new unsigned char[numWChars * 4 + 1];
|
uint16_t *temp = new uint16_t[ numWChars ];
|
||||||
uint16_t *temp = new uint16_t[numWChars];
|
for ( uint32_t n = 0; n < numWChars; ++n ) {
|
||||||
for (uint32_t n=0;n<numWChars;n++)
|
temp[ n ] = stream->GetU2();
|
||||||
temp[n] = stream->GetU2();
|
}
|
||||||
|
|
||||||
// Convert it and NUL-terminate.
|
// 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.
|
// Return the final string.
|
||||||
aiString result = aiString((const char *)&str[0]);
|
aiString result = aiString((const char *)&str[0]);
|
||||||
//delete[] str;
|
|
||||||
delete[] temp;
|
delete[] temp;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,26 +216,26 @@ SIBImporter::~SIBImporter() {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns whether the class can handle the format of the given file.
|
// 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");
|
return SimpleExtensionCheck(pFile, "sib");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
const aiImporterDesc* SIBImporter::GetInfo () const
|
const aiImporterDesc* SIBImporter::GetInfo () const {
|
||||||
{
|
|
||||||
return &desc;
|
return &desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
static void ReadVerts(SIBMesh* mesh, StreamReaderLE* stream, uint32_t count)
|
static void ReadVerts(SIBMesh* mesh, StreamReaderLE* stream, uint32_t count) {
|
||||||
{
|
if ( nullptr == mesh || nullptr == stream ) {
|
||||||
mesh->pos.resize(count);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t n=0;n<count;n++) {
|
mesh->pos.resize(count);
|
||||||
mesh->pos[n].x = stream->GetF4();
|
for ( uint32_t n=0; n<count; ++n ) {
|
||||||
mesh->pos[n].y = stream->GetF4();
|
mesh->pos[ n ].x = stream->GetF4();
|
||||||
mesh->pos[n].z = stream->GetF4();
|
mesh->pos[ n ].y = stream->GetF4();
|
||||||
|
mesh->pos[ n ].z = stream->GetF4();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,15 +291,11 @@ private:
|
||||||
throw DeadlyImportError("End of file or stream limit was reached");
|
throw DeadlyImportError("End of file or stream limit was reached");
|
||||||
}
|
}
|
||||||
|
|
||||||
///*#ifdef __arm__
|
|
||||||
T f;
|
T f;
|
||||||
::memcpy (&f, current, sizeof(T));
|
::memcpy (&f, current, sizeof(T));
|
||||||
//#else*/
|
Intern::Getter<SwapEndianess,T,RuntimeSwitch>() (&f,le);
|
||||||
// T f = *((const T*)current);
|
|
||||||
//#endif
|
|
||||||
Intern :: Getter<SwapEndianess,T,RuntimeSwitch>() (&f,le);
|
|
||||||
|
|
||||||
current += sizeof(T);
|
current += sizeof(T);
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue