]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - image.c
Catch bad pointers when loading corrupt TGAs
[xonotic/darkplaces.git] / 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;