Skip to content

Commit

Permalink
GdfxFileSystem: Truncate file if the stream ends before the declared …
Browse files Browse the repository at this point in the history
…size
  • Loading branch information
rapperskull committed Mar 2, 2023
1 parent e9d61cb commit d57bb9a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions GdfxFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ public bool Read(Stream stream)
stream.Read(fileNameBytes, 0, DirEntry.FileNameLength);
fileName = Encoding.ASCII.GetString(fileNameBytes);

if(FileSystem.GdfSectorToAddress(DirEntry.FirstSector) + DirEntry.FileSize > (ulong)stream.Length)
{
// The stream ends before the file, truncate it
DirEntry.FileSize = (uint)((ulong)stream.Length - FileSystem.GdfSectorToAddress(DirEntry.FirstSector));
}

// Align code from Velocity, seems to work great
stream.Position = (long)((ulong)(DirEntryAddr + DirEntry.FileNameLength + 0x11) & 0xFFFFFFFFFFFFFFFC);
return true;
Expand Down

0 comments on commit d57bb9a

Please sign in to comment.