Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix div-by-zero errors on files which don't have any changed content #7

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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