Fix: Add check for invalid input argument
parent
7b6bf139cf
commit
d7cde43367
|
@ -3,7 +3,7 @@
|
||||||
Open Asset Import Library (assimp)
|
Open Asset Import Library (assimp)
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2006-2022, assimp team
|
Copyright (c) 2006-2023, assimp team
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ MD5Parser::MD5Parser(char *_buffer, unsigned int _fileSize) : buffer(_buffer), b
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Report error to the log stream
|
// Report error to the log stream
|
||||||
/*static*/ AI_WONT_RETURN void MD5Parser::ReportError(const char *error, unsigned int line) {
|
AI_WONT_RETURN void MD5Parser::ReportError(const char *error, unsigned int line) {
|
||||||
char szBuffer[1024];
|
char szBuffer[1024];
|
||||||
::ai_snprintf(szBuffer, 1024, "[MD5] Line %u: %s", line, error);
|
::ai_snprintf(szBuffer, 1024, "[MD5] Line %u: %s", line, error);
|
||||||
throw DeadlyImportError(szBuffer);
|
throw DeadlyImportError(szBuffer);
|
||||||
|
@ -95,7 +95,7 @@ MD5Parser::MD5Parser(char *_buffer, unsigned int _fileSize) : buffer(_buffer), b
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Report warning to the log stream
|
// Report warning to the log stream
|
||||||
/*static*/ void MD5Parser::ReportWarning(const char *warn, unsigned int line) {
|
void MD5Parser::ReportWarning(const char *warn, unsigned int line) {
|
||||||
char szBuffer[1024];
|
char szBuffer[1024];
|
||||||
::snprintf(szBuffer, sizeof(szBuffer), "[MD5] Line %u: %s", line, warn);
|
::snprintf(szBuffer, sizeof(szBuffer), "[MD5] Line %u: %s", line, warn);
|
||||||
ASSIMP_LOG_WARN(szBuffer);
|
ASSIMP_LOG_WARN(szBuffer);
|
||||||
|
@ -122,8 +122,8 @@ void MD5Parser::ParseHeader() {
|
||||||
// print the command line options to the console
|
// print the command line options to the console
|
||||||
// FIX: can break the log length limit, so we need to be careful
|
// FIX: can break the log length limit, so we need to be careful
|
||||||
char *sz = buffer;
|
char *sz = buffer;
|
||||||
while (!IsLineEnd(*buffer++))
|
while (!IsLineEnd(*buffer++));
|
||||||
;
|
|
||||||
ASSIMP_LOG_INFO(std::string(sz, std::min((uintptr_t)MAX_LOG_MESSAGE_LENGTH, (uintptr_t)(buffer - sz))));
|
ASSIMP_LOG_INFO(std::string(sz, std::min((uintptr_t)MAX_LOG_MESSAGE_LENGTH, (uintptr_t)(buffer - sz))));
|
||||||
SkipSpacesAndLineEnd();
|
SkipSpacesAndLineEnd();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
Open Asset Import Library (assimp)
|
Open Asset Import Library (assimp)
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2006-2022, assimp team
|
Copyright (c) 2006-2023, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
|
@ -93,7 +92,7 @@ struct Section {
|
||||||
std::string mName;
|
std::string mName;
|
||||||
|
|
||||||
//! For global elements: the value of the element as string
|
//! For global elements: the value of the element as string
|
||||||
//! Iif !length() the section is not a global element
|
//! if !length() the section is not a global element
|
||||||
std::string mGlobalValue;
|
std::string mGlobalValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -349,7 +348,6 @@ public:
|
||||||
*/
|
*/
|
||||||
MD5Parser(char* buffer, unsigned int fileSize);
|
MD5Parser(char* buffer, unsigned int fileSize);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Report a specific error message and throw an exception
|
/** Report a specific error message and throw an exception
|
||||||
* @param error Error message to be reported
|
* @param error Error message to be reported
|
||||||
|
@ -364,47 +362,47 @@ public:
|
||||||
*/
|
*/
|
||||||
static void ReportWarning(const char* warn, unsigned int line);
|
static void ReportWarning(const char* warn, unsigned int line);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
/** Report a specific error
|
||||||
|
* @param error Error message to be reported
|
||||||
|
*/
|
||||||
AI_WONT_RETURN void ReportError (const char* error) AI_WONT_RETURN_SUFFIX;
|
AI_WONT_RETURN void ReportError (const char* error) AI_WONT_RETURN_SUFFIX;
|
||||||
|
|
||||||
void ReportWarning (const char* warn) {
|
// -------------------------------------------------------------------
|
||||||
return ReportWarning(warn, lineNumber);
|
/** Report a specific warning
|
||||||
}
|
* @param error Warn message to be reported
|
||||||
|
*/
|
||||||
|
void ReportWarning (const char* warn);
|
||||||
|
|
||||||
//! List of all sections which have been read
|
//! List of all sections which have been read
|
||||||
SectionList mSections;
|
SectionList mSections;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// -------------------------------------------------------------------
|
|
||||||
/** Parses a file section. The current file pointer must be outside
|
|
||||||
* of a section.
|
|
||||||
* @param out Receives the section data
|
|
||||||
* @return true if the end of the file has been reached
|
|
||||||
* @throws ImportErrorException if an error occurs
|
|
||||||
*/
|
|
||||||
bool ParseSection(Section& out);
|
bool ParseSection(Section& out);
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
|
||||||
/** Parses the file header
|
|
||||||
* @throws ImportErrorException if an error occurs
|
|
||||||
*/
|
|
||||||
void ParseHeader();
|
void ParseHeader();
|
||||||
|
|
||||||
bool SkipLine(const char* in, const char** out);
|
bool SkipLine(const char* in, const char** out);
|
||||||
bool SkipLine( );
|
bool SkipLine( );
|
||||||
bool SkipSpacesAndLineEnd( const char* in, const char** out);
|
bool SkipSpacesAndLineEnd( const char* in, const char** out);
|
||||||
bool SkipSpacesAndLineEnd();
|
bool SkipSpacesAndLineEnd();
|
||||||
bool SkipSpaces();
|
bool SkipSpaces();
|
||||||
|
|
||||||
|
private:
|
||||||
char* buffer;
|
char* buffer;
|
||||||
char* bufferEnd;
|
char* bufferEnd;
|
||||||
unsigned int fileSize;
|
unsigned int fileSize;
|
||||||
unsigned int lineNumber;
|
unsigned int lineNumber;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
inline void MD5Parser::ReportWarning (const char* warn) {
|
||||||
|
return ReportWarning(warn, lineNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------
|
||||||
inline void MD5Parser::ReportError(const char* error) {
|
inline void MD5Parser::ReportError(const char* error) {
|
||||||
ReportError(error, lineNumber);
|
ReportError(error, lineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
inline bool MD5Parser::SkipLine(const char* in, const char** out) {
|
inline bool MD5Parser::SkipLine(const char* in, const char** out) {
|
||||||
++lineNumber;
|
++lineNumber;
|
||||||
|
@ -418,8 +416,12 @@ inline bool MD5Parser::SkipLine( ) {
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
inline bool MD5Parser::SkipSpacesAndLineEnd( const char* in, const char** out) {
|
inline bool MD5Parser::SkipSpacesAndLineEnd( const char* in, const char** out) {
|
||||||
bool bHad = false;
|
if (in == bufferEnd) {
|
||||||
bool running = true;
|
*out = in;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bHad = false, running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
if( *in == '\r' || *in == '\n') {
|
if( *in == '\r' || *in == '\n') {
|
||||||
// we open files in binary mode, so there could be \r\n sequences ...
|
// we open files in binary mode, so there could be \r\n sequences ...
|
||||||
|
@ -427,9 +429,11 @@ inline bool MD5Parser::SkipSpacesAndLineEnd( const char* in, const char** out) {
|
||||||
bHad = true;
|
bHad = true;
|
||||||
++lineNumber;
|
++lineNumber;
|
||||||
}
|
}
|
||||||
|
} else if (*in == '\t' || *in == ' ') {
|
||||||
|
bHad = false;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (*in == '\t' || *in == ' ')bHad = false;
|
|
||||||
else break;
|
|
||||||
++in;
|
++in;
|
||||||
if (in == bufferEnd) {
|
if (in == bufferEnd) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue