changed the type of "header" in PlyFile from char [4096] to std::string to avoid buffer overrun on loading plys with veeery long comments

This commit is contained in:
Marco Callieri 2011-02-21 11:04:55 +00:00
parent 6a876e1fc9
commit 90c3924a77
2 changed files with 11 additions and 8 deletions

View File

@ -1059,7 +1059,8 @@ int PlyFile::OpenRead( const char * filename )
goto error; goto error;
} }
header[0] = 0; header.clear();
header.reserve(1536);
// ********* Parsing header *********** // ********* Parsing header ***********
@ -1069,7 +1070,8 @@ int PlyFile::OpenRead( const char * filename )
error = E_UNESPECTEDEOF; error = E_UNESPECTEDEOF;
goto error; goto error;
} }
strcat(header,buf); header.append(buf);
if( strncmp(buf,HEADER,strlen(HEADER)) ) if( strncmp(buf,HEADER,strlen(HEADER)) )
{ {
error = E_NOTHEADER; error = E_NOTHEADER;
@ -1084,7 +1086,8 @@ int PlyFile::OpenRead( const char * filename )
error = E_UNESPECTEDEOF; error = E_UNESPECTEDEOF;
goto error; goto error;
} }
strcat(header,buf); header.append(buf);
token = strtok(buf,SEP); token = strtok(buf,SEP);
if(token==0) if(token==0)
{ {
@ -1131,7 +1134,7 @@ int PlyFile::OpenRead( const char * filename )
error = E_UNESPECTEDEOF; error = E_UNESPECTEDEOF;
goto error; goto error;
} }
strcat(header,buf); header.append(buf);
token = strtok(buf,SEP); token = strtok(buf,SEP);
if(token==0) if(token==0)

View File

@ -300,7 +300,7 @@ public:
static const char * typenames[9]; static const char * typenames[9];
static const char * newtypenames[9]; static const char * newtypenames[9];
inline const char * GetHeader() const { return header; } inline const char * GetHeader() const { return header.c_str(); }
protected: protected:
GZFILE gzfp; GZFILE gzfp;
@ -309,7 +309,7 @@ protected:
int error; // Errore corrente (vedi enum) int error; // Errore corrente (vedi enum)
int format; // Formato del file (vedi enum ) int format; // Formato del file (vedi enum )
char header[4096]; // Testo dell'header std::string header; // Testo dell'header
PlyElement * cure; // Elemento da leggere PlyElement * cure; // Elemento da leggere