Skip to content

Commit

Permalink
Merge pull request #7 from AurorNZ/revert-6-revert-5-fix-div-by-zero
Browse files Browse the repository at this point in the history
Fix div-by-zero errors on files which don't have any changed content
  • Loading branch information
Obi-Dann committed Dec 7, 2020
2 parents bfcfb18 + eff6652 commit f917372
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Squirrel/BinaryPatchUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,27 @@ static void CreateInternal(byte[] oldData, byte[] newData, Stream output)
WriteInt64(controlEndPosition - startPosition - c_headerSize, header, 8);

// write compressed diff data
using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None))
using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress))
if (dblen > 0)
{
bz2Stream.Write(db, 0, dblen);
using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None))
using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress))
{
bz2Stream.Write(db, 0, dblen);
}
}

// compute size of compressed diff data
long diffEndPosition = output.Position;
WriteInt64(diffEndPosition - controlEndPosition, header, 16);

// write compressed extra data
using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None))
using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress))
if (eblen > 0)
{
bz2Stream.Write(eb, 0, eblen);
using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None))
using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress))
{
bz2Stream.Write(eb, 0, eblen);
}
}

// seek to the beginning, write the header, then seek back to end
Expand Down

0 comments on commit f917372

Please sign in to comment.