From 838abb8773721ae18b372a30cac05c1615f800fc Mon Sep 17 00:00:00 2001 From: morkt Date: Sun, 9 Oct 2016 08:44:58 +0400 Subject: [PATCH] (XoredStream): limit write buffer to 80k. --- ArcFormats/CommonStreams.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ArcFormats/CommonStreams.cs b/ArcFormats/CommonStreams.cs index 531cf83e..b2c23e07 100644 --- a/ArcFormats/CommonStreams.cs +++ b/ArcFormats/CommonStreams.cs @@ -563,13 +563,19 @@ namespace GameRes.Formats public override void Write (byte[] buffer, int offset, int count) { - if (null == write_buf || write_buf.Length < count) - write_buf = new byte[count]; - for (int i = 0; i < count; ++i) + if (null == write_buf) + write_buf = new byte[81920]; + while (count > 0) { - write_buf[i] = (byte)(buffer[offset+i] ^ m_key); + int chunk = Math.Min (write_buf.Length, count); + for (int i = 0; i < chunk; ++i) + { + write_buf[i] = (byte)(buffer[offset+i] ^ m_key); + } + BaseStream.Write (write_buf, 0, count); + offset += chunk; + count -= chunk; } - BaseStream.Write (write_buf, 0, count); } public override void WriteByte (byte value)