Skip to content

Commit

Permalink
fix: prevent overflow in throttled stream
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Mar 10, 2024
1 parent 1d64e35 commit 7cca999
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Util/GloballyThrottledStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public override int Read(byte[] buffer, int offset, int count) {
// wait until between 1 and 65536 bytes are available, depending on
// the buffer size and the speed limit
var mbps = MaxBytesPerSecond;
var exp = (int) Math.Truncate(Math.Log2(Math.Min(count, (int) mbps)));
var exp = (int) Math.Truncate(Math.Log2(Math.Min((ulong) count, mbps)));
var wanted = (ulong) Math.Pow(2, Math.Clamp(exp, 0, 16));
return (mbps, Math.Min(wanted, (ulong) count));
}
Expand Down

0 comments on commit 7cca999

Please sign in to comment.