-Fixes in new resource file code: Added file length checks and set lump count to 1 for single lump files.

SVN r1558 (trunk)
This commit is contained in:
Christoph Oelckers 2009-04-24 22:31:35 +00:00
parent 1ea8777572
commit 2e90519c13
7 changed files with 61 additions and 42 deletions

View file

@ -334,14 +334,17 @@ FResourceFile *Check7Z(const char *filename, FileReader *file)
{ {
char head[k7zSignatureSize]; char head[k7zSignatureSize];
file->Seek(0, SEEK_SET); if (file->GetLength() >= k7zSignatureSize)
file->Read(&head, k7zSignatureSize);
file->Seek(0, SEEK_SET);
if (!memcmp(head, k7zSignature, k7zSignatureSize))
{ {
FResourceFile *rf = new F7ZFile(filename, file); file->Seek(0, SEEK_SET);
if (rf->Open()) return rf; file->Read(&head, k7zSignatureSize);
delete rf; file->Seek(0, SEEK_SET);
if (!memcmp(head, k7zSignature, k7zSignatureSize))
{
FResourceFile *rf = new F7ZFile(filename, file);
if (rf->Open()) return rf;
delete rf;
}
} }
return NULL; return NULL;
} }

View file

@ -138,14 +138,17 @@ FResourceFile *CheckGRP(const char *filename, FileReader *file)
{ {
char head[12]; char head[12];
file->Seek(0, SEEK_SET); if (file->GetLength() >= 12)
file->Read(&head, 12);
file->Seek(0, SEEK_SET);
if (!memcmp(head, "KenSilverman", 12))
{ {
FResourceFile *rf = new FGrpFile(filename, file); file->Seek(0, SEEK_SET);
if (rf->Open()) return rf; file->Read(&head, 12);
delete rf; file->Seek(0, SEEK_SET);
if (!memcmp(head, "KenSilverman", 12))
{
FResourceFile *rf = new FGrpFile(filename, file);
if (rf->Open()) return rf;
delete rf;
}
} }
return NULL; return NULL;
} }

View file

@ -80,6 +80,7 @@ bool FLumpFile::Open()
Lumps->Namespace = ns_global; Lumps->Namespace = ns_global;
Lumps->Flags = 0; Lumps->Flags = 0;
Lumps->FullName = NULL; Lumps->FullName = NULL;
NumLumps = 1;
return true; return true;
} }

View file

@ -130,14 +130,17 @@ FResourceFile *CheckPak(const char *filename, FileReader *file)
{ {
char head[4]; char head[4];
file->Seek(0, SEEK_SET); if (file->GetLength() >= 12)
file->Read(&head, 4);
file->Seek(0, SEEK_SET);
if (!memcmp(head, "PACK", 4))
{ {
FResourceFile *rf = new FPakFile(filename, file); file->Seek(0, SEEK_SET);
if (rf->Open()) return rf; file->Read(&head, 4);
delete rf; file->Seek(0, SEEK_SET);
if (!memcmp(head, "PACK", 4))
{
FResourceFile *rf = new FPakFile(filename, file);
if (rf->Open()) return rf;
delete rf;
}
} }
return NULL; return NULL;
} }

View file

@ -235,14 +235,17 @@ FResourceFile *CheckRFF(const char *filename, FileReader *file)
{ {
char head[4]; char head[4];
file->Seek(0, SEEK_SET); if (file->GetLength() >= 16)
file->Read(&head, 4);
file->Seek(0, SEEK_SET);
if (!memcmp(head, "RFF\x1a", 4))
{ {
FResourceFile *rf = new FRFFFile(filename, file); file->Seek(0, SEEK_SET);
if (rf->Open()) return rf; file->Read(&head, 4);
delete rf; file->Seek(0, SEEK_SET);
if (!memcmp(head, "RFF\x1a", 4))
{
FResourceFile *rf = new FRFFFile(filename, file);
if (rf->Open()) return rf;
delete rf;
}
} }
return NULL; return NULL;
} }

View file

@ -328,14 +328,17 @@ FResourceFile *CheckWad(const char *filename, FileReader *file)
{ {
char head[4]; char head[4];
file->Seek(0, SEEK_SET); if (file->GetLength() >= 12)
file->Read(&head, 4);
file->Seek(0, SEEK_SET);
if (!memcmp(head, "IWAD", 4) || !memcmp(head, "PWAD", 4))
{ {
FResourceFile *rf = new FWadFile(filename, file); file->Seek(0, SEEK_SET);
if (rf->Open()) return rf; file->Read(&head, 4);
delete rf; file->Seek(0, SEEK_SET);
if (!memcmp(head, "IWAD", 4) || !memcmp(head, "PWAD", 4))
{
FResourceFile *rf = new FWadFile(filename, file);
if (rf->Open()) return rf;
delete rf;
}
} }
return NULL; return NULL;
} }

View file

@ -391,14 +391,17 @@ FResourceFile *CheckZip(const char *filename, FileReader *file)
{ {
char head[4]; char head[4];
file->Seek(0, SEEK_SET); if (file->GetLength() >= sizeof(FZipLocalFileHeader))
file->Read(&head, 4);
file->Seek(0, SEEK_SET);
if (!memcmp(head, "PK\x3\x4", 4))
{ {
FResourceFile *rf = new FZipFile(filename, file); file->Seek(0, SEEK_SET);
if (rf->Open()) return rf; file->Read(&head, 4);
delete rf; file->Seek(0, SEEK_SET);
if (!memcmp(head, "PK\x3\x4", 4))
{
FResourceFile *rf = new FZipFile(filename, file);
if (rf->Open()) return rf;
delete rf;
}
} }
return NULL; return NULL;
} }