]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Catch bad pointers when loading corrupt TGAs
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 20 Jun 2010 15:26:32 +0000 (15:26 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 20 Jun 2010 15:26:32 +0000 (15:26 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10240 d7cf8633-e32d-0410-b094-e92efae38249

image.c

diff --git a/image.c b/image.c
index ccc59f2eeff3e99dfd1c6473e28c5a779f4dfe86..3c061de12df5dcb2c399625a5c36d3413107ded6 100644 (file)
--- a/image.c
+++ b/image.c
@@ -609,6 +609,13 @@ unsigned char *LoadTGA_BGRA (const unsigned char *f, int filesize)
                                                *pixbufi++ = palettei[*fin++];
                                }
                        }
+
+                       if (x != image_width)
+                       {
+                               // pixbufi is useless now
+                               Con_Printf("LoadTGA: corrupt file\n");
+                               break;
+                       }
                }
                break;
        case 10:
@@ -657,6 +664,13 @@ unsigned char *LoadTGA_BGRA (const unsigned char *f, int filesize)
                                                }
                                        }
                                }
+
+                               if (x != image_width)
+                               {
+                                       // pixbufi is useless now
+                                       Con_Printf("LoadTGA: corrupt file\n");
+                                       break;
+                               }
                        }
                }
                else
@@ -703,6 +717,13 @@ unsigned char *LoadTGA_BGRA (const unsigned char *f, int filesize)
                                                }
                                        }
                                }
+
+                               if (x != image_width)
+                               {
+                                       // pixbufi is useless now
+                                       Con_Printf("LoadTGA: corrupt file\n");
+                                       break;
+                               }
                        }
                }
                break;