From 5d087791d02fe44879decda7ab78dd8d4aa95fa4 Mon Sep 17 00:00:00 2001 From: Kenneth Hsu Date: Sun, 7 Jul 2019 16:04:36 -0700 Subject: [PATCH] Fix bug in ThrottledStream.Write method. Prior to revision 0190a9994e ("Rewrote the throttling implementation to be more effecient"), the DelayIfRequired method would increment the offset variable to advance through the buffer. When we modified the implementation in revision 0190a9994e, we may have forgotten to modify the offset accordingly. --- Duplicati/Library/Utility/ThrottledStream.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Duplicati/Library/Utility/ThrottledStream.cs b/Duplicati/Library/Utility/ThrottledStream.cs index 7f30856ec..5a681baec 100644 --- a/Duplicati/Library/Utility/ThrottledStream.cs +++ b/Duplicati/Library/Utility/ThrottledStream.cs @@ -153,7 +153,8 @@ namespace Duplicati.Library.Utility /// The offset into the buffer. /// The number of bytes to write. public override void Write(byte[] buffer, int offset, int count) - { + { + int bytesWritten = 0; while (count > 0) { // To avoid excessive waiting, the delay will wait at most 2 seconds, @@ -161,10 +162,10 @@ namespace Duplicati.Library.Utility UpdateLimits(); var chunksize = (int)Math.Min(count, m_writespeed <= 0 ? count : m_writespeed * 2); DelayIfRequired(ref m_writespeed, chunksize, ref m_last_write_sample, ref m_current_write_counter, ref m_current_write_speed); - m_basestream.Write(buffer, offset, chunksize); + m_basestream.Write(buffer, offset + bytesWritten, chunksize); m_current_write_counter += chunksize; - + bytesWritten += chunksize; count -= chunksize; } }