- Remove 255 character length restriction on lump names.

- Removed directory checking for big endian wads since the header check should be sufficient.

SVN r3899 (trunk)
This commit is contained in:
Braden Obrzut 2012-10-22 21:58:52 +00:00
parent 4b218c1c18
commit cd2c1f6816
4 changed files with 28 additions and 63 deletions

View File

@ -271,7 +271,6 @@ bool F7ZFile::Open(bool quiet)
for (DWORD i = 0; i < NumLumps; ++i)
{
CSzFileItem *file = &Archive->DB.db.Files[i];
char name[256];
// skip Directories
if (file->IsDir)
@ -280,10 +279,9 @@ bool F7ZFile::Open(bool quiet)
continue;
}
strncpy(name, file->Name, countof(name)-1);
name[countof(name)-1] = 0;
FString name = file->Name;
FixPathSeperator(name);
strlwr(name);
name.ToLower();
lump_p->LumpNameSetup(name);
lump_p->LumpSize = int(file->Size);

View File

@ -336,7 +336,7 @@ bool FWadFile::Open(bool quiet)
InfoTableOfs = LittleLong(header.InfoTableOfs);
// Check to see if the little endian interpretation is valid
// This should detect most big endian wads
// This should be sufficient to detect big endian wads.
if (InfoTableOfs + NumLumps*sizeof(wadlump_t) > (unsigned)wadSize)
{
NumLumps = BigLong(header.NumLumps);
@ -344,53 +344,28 @@ bool FWadFile::Open(bool quiet)
isBigEndian = true;
}
// Read the directory. If we're still assuming little endian and the lump
// is out of range then we switch to big endian mode and try again.
do
wadlump_t *fileinfo = new wadlump_t[NumLumps];
Reader->Seek (InfoTableOfs, SEEK_SET);
Reader->Read (fileinfo, NumLumps * sizeof(wadlump_t));
Lumps = new FWadFileLump[NumLumps];
for(DWORD i = 0; i < NumLumps; i++)
{
wadlump_t *fileinfo = new wadlump_t[NumLumps];
Reader->Seek (InfoTableOfs, SEEK_SET);
Reader->Read (fileinfo, NumLumps * sizeof(wadlump_t));
uppercopy (Lumps[i].Name, fileinfo[i].Name);
Lumps[i].Name[8] = 0;
Lumps[i].Compressed = Lumps[i].Name[0] & 0x80;
Lumps[i].Name[0] &= ~0x80;
Lumps = new FWadFileLump[NumLumps];
bool valid = true;
for(DWORD i = 0; i < NumLumps; i++)
{
uppercopy (Lumps[i].Name, fileinfo[i].Name);
Lumps[i].Name[8] = 0;
Lumps[i].Compressed = Lumps[i].Name[0] & 0x80;
Lumps[i].Name[0] &= ~0x80;
Lumps[i].Owner = this;
Lumps[i].Position = isBigEndian ? BigLong(fileinfo[i].FilePos) : LittleLong(fileinfo[i].FilePos);
Lumps[i].LumpSize = isBigEndian ? BigLong(fileinfo[i].Size) : LittleLong(fileinfo[i].Size);
if(Lumps[i].Position > wadSize || Lumps[i].Position + Lumps[i].LumpSize > wadSize)
{
valid = false;
break;
}
Lumps[i].Namespace = ns_global;
Lumps[i].Flags = 0;
Lumps[i].FullName = NULL;
}
delete[] fileinfo;
if(!valid)
{
if(isBigEndian)
return false;
delete[] Lumps;
NumLumps = BigLong(header.NumLumps);
InfoTableOfs = BigLong(header.InfoTableOfs);
isBigEndian = true;
continue;
}
break;
Lumps[i].Owner = this;
Lumps[i].Position = isBigEndian ? BigLong(fileinfo[i].FilePos) : LittleLong(fileinfo[i].FilePos);
Lumps[i].LumpSize = isBigEndian ? BigLong(fileinfo[i].Size) : LittleLong(fileinfo[i].Size);
Lumps[i].Namespace = ns_global;
Lumps[i].Flags = 0;
Lumps[i].FullName = NULL;
}
while(true);
delete[] fileinfo;
if (!quiet)
{

View File

@ -210,11 +210,8 @@ bool FZipFile::Open(bool quiet)
{
FZipCentralDirectoryInfo *zip_fh = (FZipCentralDirectoryInfo *)dirptr;
char name[256];
int len = LittleShort(zip_fh->NameLength);
strncpy(name, dirptr + sizeof(FZipCentralDirectoryInfo), MIN<int>(len, 255));
name[len] = 0;
FString name(dirptr + sizeof(FZipCentralDirectoryInfo), len);
dirptr += sizeof(FZipCentralDirectoryInfo) +
LittleShort(zip_fh->NameLength) +
LittleShort(zip_fh->ExtraLength) +
@ -236,7 +233,7 @@ bool FZipFile::Open(bool quiet)
zip_fh->Method != METHOD_IMPLODE &&
zip_fh->Method != METHOD_SHRINK)
{
if (!quiet) Printf("\n%s: '%s' uses an unsupported compression algorithm (#%d).\n", Filename, name, zip_fh->Method);
if (!quiet) Printf("\n%s: '%s' uses an unsupported compression algorithm (#%d).\n", Filename, name.GetChars(), zip_fh->Method);
skipped++;
continue;
}
@ -244,13 +241,13 @@ bool FZipFile::Open(bool quiet)
zip_fh->Flags = LittleShort(zip_fh->Flags);
if (zip_fh->Flags & ZF_ENCRYPTED)
{
if (!quiet) Printf("\n%s: '%s' is encrypted. Encryption is not supported.\n", Filename, name);
if (!quiet) Printf("\n%s: '%s' is encrypted. Encryption is not supported.\n", Filename, name.GetChars());
skipped++;
continue;
}
FixPathSeperator(name);
strlwr(name);
name.ToLower();
lump_p->LumpNameSetup(name);
lump_p->LumpSize = LittleLong(zip_fh->UncompressedSize);

View File

@ -96,15 +96,10 @@ FResourceLump::~FResourceLump()
void FResourceLump::LumpNameSetup(const char *iname)
{
char base[256];
const char *lname = strrchr(iname,'/');
lname = (lname == NULL) ? iname : lname + 1;
strcpy(base, lname);
char *dot = strrchr(base, '.');
if (dot != NULL)
{
*dot = 0;
}
FString base = lname;
base = base.Left(base.LastIndexOf('.'));
uppercopy(Name, base);
Name[8] = 0;
FullName = copystring(iname);