From 90c3924a7783f23657fb3aab6227efa31a6f9b1a Mon Sep 17 00:00:00 2001 From: mcallieri Date: Mon, 21 Feb 2011 11:04:55 +0000 Subject: [PATCH] changed the type of "header" in PlyFile from char [4096] to std::string to avoid buffer overrun on loading plys with veeery long comments --- wrap/ply/plylib.cpp | 11 +++++++---- wrap/ply/plylib.h | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/wrap/ply/plylib.cpp b/wrap/ply/plylib.cpp index cd288706..958b5f1a 100644 --- a/wrap/ply/plylib.cpp +++ b/wrap/ply/plylib.cpp @@ -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) diff --git a/wrap/ply/plylib.h b/wrap/ply/plylib.h index 7e98d63a..8a346826 100644 --- a/wrap/ply/plylib.h +++ b/wrap/ply/plylib.h @@ -295,12 +295,12 @@ public: // Lettura du un elemento int Read( void * mem ); - std::vector elements; // Vettore degli elementi - std::vector comments; // Vettore dei commenti + std::vector elements; // Vettore degli elementi + std::vector 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