From 36b2046f57879ab51ff606f67ee6731b03035688 Mon Sep 17 00:00:00 2001 From: Shpoike Date: Fri, 19 Jun 2020 21:21:00 +0100 Subject: [PATCH] Be more verbose and less errory about corrupt gfx.wad files. --- Quake/gl_draw.c | 2 +- Quake/wad.c | 33 +++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Quake/gl_draw.c b/Quake/gl_draw.c index 9a322799..0958a09e 100644 --- a/Quake/gl_draw.c +++ b/Quake/gl_draw.c @@ -419,7 +419,7 @@ void Draw_LoadPics (void) data = (byte *) W_GetLumpName ("conchars", &info); if (!data || info->size < 128*128) Sys_Error ("Draw_LoadPics: couldn't load conchars"); - if (info->size != 128*128) Con_Warning("Invalid size for gfx.wad conchars lump - attempting to ignore for compat.\n"); + if (info->size != 128*128) Con_Warning("Invalid size for gfx.wad conchars lump (%u, expected %u) - attempting to ignore for compat.\n", info->size, 128*128); else if (info->type != TYP_MIPTEX) Con_DWarning("Invalid type for gfx.wad conchars lump - attempting to ignore for compat.\n"); //not really a miptex, but certainly NOT a qpic. offset = (src_offset_t)data - (src_offset_t)wad_base; char_texture = TexMgr_LoadImage (NULL, WADFILENAME":conchars", 128, 128, SRC_INDEXED, data, diff --git a/Quake/wad.c b/Quake/wad.c index ba1b543e..30f2a77d 100644 --- a/Quake/wad.c +++ b/Quake/wad.c @@ -89,20 +89,41 @@ void W_LoadWadFile (void) //johnfitz -- filename is now hard-coded for honesty if (header->identification[0] != 'W' || header->identification[1] != 'A' || header->identification[2] != 'D' || header->identification[3] != '2') - Sys_Error ("Wad file %s doesn't have WAD2 id\n",filename); - - wad_numlumps = LittleLong(header->numlumps); - infotableofs = LittleLong(header->infotableofs); + { + Con_Printf ("Wad file %s doesn't have WAD2 id\n",filename); + wad_numlumps = 0; + infotableofs = 0; + } + else + { + wad_numlumps = LittleLong(header->numlumps); + infotableofs = LittleLong(header->infotableofs); + } wad_lumps = (lumpinfo_t *)(wad_base + infotableofs); if (infotableofs < 0 || infotableofs+wad_numlumps*sizeof(lumpinfo_t)>com_filesize) - Sys_Error ("Wad file %s header extends beyond end of file\n",filename); + { + Con_Printf ("Wad file %s header extends beyond end of file\n",filename); + wad_numlumps = 0; + } for (i=0, lump_p = wad_lumps ; ifilepos = LittleLong(lump_p->filepos); lump_p->size = LittleLong(lump_p->size); if (lump_p->filepos < 0 || lump_p->size < 0 || lump_p->filepos + lump_p->size > com_filesize) - Sys_Error ("Wad file %s lump \"%16s\" extends beyond end of file\n",filename, lump_p->name); + { + if (lump_p->filepos > com_filesize || lump_p->size < 0) + { + Con_Printf ("Wad file %s lump \"%.16s\" begins %u bytes beyond end of wad\n",filename, lump_p->name, lump_p->filepos - com_filesize); + lump_p->filepos = 0; + lump_p->size = q_max(0, lump_p->size-lump_p->filepos); + } + else + { + Con_Printf ("Wad file %s lump \"%.16s\" extends %u bytes beyond end of wad (lump size: %u)\n",filename, lump_p->name, (lump_p->filepos + lump_p->size) - com_filesize, lump_p->size); + lump_p->size = q_max(0, lump_p->size-lump_p->filepos); + } + } W_CleanupName (lump_p->name, lump_p->name); // CAUTION: in-place editing!!! The endian fixups too. if (lump_p->type == TYP_QPIC) SwapPic ( (qpic_t *)(wad_base + lump_p->filepos));