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

View File

@ -295,12 +295,12 @@ public:
// Lettura du un elemento
int Read( void * mem );
std::vector<PlyElement> elements; // Vettore degli elementi
std::vector<std::string> comments; // Vettore dei commenti
std::vector<PlyElement> elements; // Vettore degli elementi
std::vector<std::string> comments; // Vettore dei commenti
static const char * typenames[9];
static const char * newtypenames[9];
inline const char * GetHeader() const { return header; }
inline const char * GetHeader() const { return header.c_str(); }
protected:
GZFILE gzfp;
@ -309,7 +309,7 @@ protected:
int error; // Errore corrente (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