Skip to content

Commit

Permalink
- fixed reading of extended EndOfCentralDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Apr 8, 2022
1 parent 167e043 commit 5ba048e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions source/common/filesystem/file_zip.cpp
Expand Up @@ -145,16 +145,18 @@ static uint32_t Zip_FindCentralDir(FileReader &fin, bool* zip64)

for (i = (int)uReadSize - 3; (i--) > 0;)
{
if (buf[i] == 'P' && buf[i+1] == 'K' && (buf[i+2] == 5 || buf[i+2] == 6) && buf[i+3] == 6)
if (buf[i] == 'P' && buf[i+1] == 'K' && buf[i+2] == 5 && buf[i+3] == 6 && !*zip64 && uPosFound == 0)
{
*zip64 = buf[i+2] == 6;
*zip64 = false;
uPosFound = uReadPos + i;
break;
}
if (buf[i] == 'P' && buf[i+1] == 'K' && buf[i+2] == 6 && buf[i+3] == 6)
{
*zip64 = true;
uPosFound = uReadPos + i;
return uPosFound;
}
}

if (uPosFound != 0)
break;
}
return uPosFound;
}
Expand Down Expand Up @@ -210,7 +212,7 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter)
FZipEndOfCentralDirectory64 info;
// Read the central directory info.
Reader.Seek(centraldir, FileReader::SeekSet);
Reader.Read(&info, sizeof(FZipEndOfCentralDirectory));
Reader.Read(&info, sizeof(FZipEndOfCentralDirectory64));

// No multi-disk zips!
if (info.NumEntries != info.NumEntriesOnAllDisks ||
Expand All @@ -220,7 +222,7 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter)
return false;
}

NumLumps = LittleLong(info.NumEntries);
NumLumps = info.NumEntries;
dirsize = info.DirectorySize;
DirectoryOffset = info.DirectoryOffset;
}
Expand Down
6 changes: 3 additions & 3 deletions source/common/filesystem/w_zip.h
Expand Up @@ -20,13 +20,13 @@ struct FZipEndOfCentralDirectory
struct FZipEndOfCentralDirectory64
{
uint32_t Magic;
uint32_t StructSize;
uint64_t StructSize;
uint16_t VersionMadeBy;
uint16_t VersionNeeded;
uint32_t DiskNumber;
uint32_t FirstDisk;
uint32_t NumEntries;
uint32_t NumEntriesOnAllDisks;
uint64_t NumEntries;
uint64_t NumEntriesOnAllDisks;
uint64_t DirectorySize;
uint64_t DirectoryOffset;
uint16_t ZipCommentLength;
Expand Down

0 comments on commit 5ba048e

Please sign in to comment.