fixed crash when loading invalid ASE models
authorspog <spog>
Sun, 19 Feb 2006 16:43:59 +0000 (16:43 +0000)
committerspog <spog>
Sun, 19 Feb 2006 16:43:59 +0000 (16:43 +0000)
git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@12 8a3a26a2-13c4-0310-b231-cf6edde360e5

CHANGES
libs/picomodel/picomodel.c
libs/picomodel/pm_ase.c
radiant/GtkRadiant.vcproj
radiant/console.cpp

diff --git a/CHANGES b/CHANGES
index 7038429..7165be6 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
 This is the changelog for developers, != changelog for the end user 
 that we distribute with the binaries. (see changelog)
 
+19/02/2006
+SPoG
+- Fixed crash when loading invalid ASE models.
+
 11/02/2006
 SPoG
 - Added install.py script.
index 618cc8a..240d729 100644 (file)
@@ -295,7 +295,10 @@ picoModel_t        *PicoModuleLoadModelStream( const picoModule_t* module, void* inputS
                model = PicoModuleLoadModel(module, fileName, buffer, bufSize, frameNum);
        }
        
-       _pico_free(buffer);
+  if(model != 0)
+  {
+         _pico_free(buffer);
+  }
 
        /* return */
        return model;
index afcf550..2450075 100644 (file)
@@ -755,19 +755,19 @@ static picoModel_t *_ase_load( PM_PARAMS_LOAD )
                        int                     index;
 
                        if( numVertices == 0 )
-                               _ase_error_return("Vertex parse error");
+                               _ase_error_return("Texture Vertex parse error");
 
                        /* get uv vertex index */
-                       if (!_pico_parse_int( p,&index ))
-                               _ase_error_return("UV vertex parse error");
+                       if (!_pico_parse_int( p,&index ) || index >= numTextureVertices)
+                               _ase_error_return("Texture vertex parse error");
 
                        /* get uv vertex s */
                        if (!_pico_parse_float( p,&texcoords[index].texcoord[0] ))
-                               _ase_error_return("UV vertex parse error");
+                               _ase_error_return("Texture vertex parse error");
 
                        /* get uv vertex t */
                        if (!_pico_parse_float( p,&texcoords[index].texcoord[1] ))
-                               _ase_error_return("UV vertex parse error");
+                               _ase_error_return("Texture vertex parse error");
                        
                        /* ydnar: invert t */
                        texcoords[index].texcoord[ 1 ] = 1.0f - texcoords[index].texcoord[ 1 ];
index 09856f9..461793e 100644 (file)
@@ -644,7 +644,7 @@ copy &quot;$(TargetDir)$(TargetName).pdb&quot;  &quot;$(SolutionDir)install&quot
                        </File>\r
                </Filter>\r
                <File\r
-                       RelativePath="..\docs\developer\Changes">\r
+                       RelativePath="..\Changes">\r
                </File>\r
                <File\r
                        RelativePath="..\debug.py">\r
@@ -683,7 +683,7 @@ copy &quot;$(TargetDir)$(TargetName).pdb&quot;  &quot;$(SolutionDir)install&quot
                        RelativePath="..\SConstruct">\r
                </File>\r
                <File\r
-                       RelativePath="..\docs\developer\Todo">\r
+                       RelativePath="..\Todo">\r
                </File>\r
                <File\r
                        RelativePath="..\touch.py">\r
index df75c61..5c46240 100644 (file)
@@ -137,6 +137,22 @@ GtkWidget* Console_constructWindow(GtkWindow* toplevel)
   return scr;
 }
 
+class GtkTextBufferOutputStream : public TextOutputStream
+{
+  GtkTextBuffer* textBuffer;
+  GtkTextIter* iter;
+  GtkTextTag* tag;
+public:
+  GtkTextBufferOutputStream(GtkTextBuffer* textBuffer, GtkTextIter* iter, GtkTextTag* tag) : textBuffer(textBuffer), iter(iter), tag(tag)
+  {
+  }
+  std::size_t write(const char* buffer, std::size_t length)
+  {
+    gtk_text_buffer_insert_with_tags(textBuffer, iter, buffer, gint(length), tag, 0);
+    return length;
+  }
+};
+
 std::size_t Sys_Print(int level, const char* buf, std::size_t length)
 {
   bool contains_newline = strchr(buf, '\n') != 0;
@@ -190,18 +206,16 @@ std::size_t Sys_Print(int level, const char* buf, std::size_t length)
       }
 
 
-      StringOutputStream converted;
+      GtkTextBufferOutputStream textBuffer(buffer, &iter, tag);
       if(!globalCharacterSet().isUTF8())
       {
-        converted << ConvertLocaleToUTF8(StringRange(buf, buf + length));
+        textBuffer << ConvertLocaleToUTF8(StringRange(buf, buf + length));
       }
       else
       {
-        converted << StringRange(buf, buf + length);
+        textBuffer << StringRange(buf, buf + length);
       }
 
-      gtk_text_buffer_insert_with_tags(buffer, &iter, converted.c_str(), gint(string_length(converted.c_str())), tag, 0);
-
       // update console widget immediatly if we're doing something time-consuming
       if(contains_newline)
       {