From 98d0c47cfb4b158406f30ffd6f85f982ffa89c8f Mon Sep 17 00:00:00 2001 From: morkt Date: Wed, 14 Sep 2016 20:08:13 +0400 Subject: [PATCH] (Adler32): skip checksum update for zero-length arrays. --- GameRes/Checksum.cs | 4 ++++ GameRes/ZLibStream.cs | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/GameRes/Checksum.cs b/GameRes/Checksum.cs index d6bbb257..435b3dd9 100644 --- a/GameRes/Checksum.cs +++ b/GameRes/Checksum.cs @@ -114,6 +114,8 @@ namespace GameRes.Utility public static uint Compute (byte[] buf, int pos, int len) { + if (0 == len) + return 1; unsafe { fixed (byte* ptr = &buf[pos]) @@ -224,6 +226,8 @@ namespace GameRes.Utility public void Update (byte[] buf, int pos, int len) { + if (0 == len) + return; unsafe { fixed (byte* ptr = &buf[pos]) diff --git a/GameRes/ZLibStream.cs b/GameRes/ZLibStream.cs index 0beb7a4b..3e7ff6db 100644 --- a/GameRes/ZLibStream.cs +++ b/GameRes/ZLibStream.cs @@ -179,8 +179,11 @@ namespace GameRes.Compression public override void Write (byte[] buffer, int offset, int count) { - m_adler.Write (buffer, offset, count); - m_total_in += count; + if (count > 0) + { + m_adler.Write (buffer, offset, count); + m_total_in += count; + } } public override void WriteByte (byte value)