Skip to content

Commit

Permalink
Fix typo & EndOfStream exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlamin committed Jul 9, 2024
1 parent a5903f9 commit 7695ed9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Warcraft.NET/Extensions/ExtendedIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,25 @@ public static bool SeekChunk(this BinaryReader reader, string chunkSignature, bo

try
{
var foundChuckSignature = reader.ReadBinarySignature(reverseSignature);
while (foundChuckSignature != chunkSignature)
var foundChunkSignature = reader.ReadBinarySignature(reverseSignature);
while (foundChunkSignature != chunkSignature)
{
var size = reader.ReadUInt32();

// Return if we are about to seek outside of range
if ((reader.BaseStream.Position + size) > reader.BaseStream.Length)
return false;

reader.BaseStream.Position += size;
foundChuckSignature = reader.ReadBinarySignature(reverseSignature);

// Return if we're done reading
if (reader.BaseStream.Position == reader.BaseStream.Length)
return false;

foundChunkSignature = reader.ReadBinarySignature(reverseSignature);
}

if (foundChuckSignature == chunkSignature)
if (foundChunkSignature == chunkSignature)
{
if (!skipSignature)
reader.BaseStream.Position -= sizeof(uint);
Expand Down

0 comments on commit 7695ed9

Please sign in to comment.