From 0693ad04453474ee3d7cafe071d0e7ffced58c6c Mon Sep 17 00:00:00 2001 From: Hawkynt Date: Sun, 15 Dec 2024 09:13:48 +0100 Subject: [PATCH 1/2] # trying to read past EOF --- Corlib.Extensions/System/IO/Stream.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Corlib.Extensions/System/IO/Stream.cs b/Corlib.Extensions/System/IO/Stream.cs index f3f6d16c..abfe6665 100644 --- a/Corlib.Extensions/System/IO/Stream.cs +++ b/Corlib.Extensions/System/IO/Stream.cs @@ -1172,7 +1172,7 @@ static byte[] StructToBytes(TStruct value) { public static void ReadBytes(this Stream @this, long position, byte[] buffer, SeekOrigin seekOrigin = SeekOrigin.Begin) { Against.False(@this.CanRead); - _SeekToPositionAndCheck(@this, position, buffer.Length, seekOrigin); + _SeekToPositionAndCheck(@this, position, (int)Math.Min(buffer.Length, @this.Length - position), seekOrigin); _ReadBytesToArraySeekable(@this, buffer, 0, buffer.Length); } From aadc17cd033229f5a66c50078e13fce1a10bc4c4 Mon Sep 17 00:00:00 2001 From: Hawkynt Date: Sun, 15 Dec 2024 12:50:11 +0100 Subject: [PATCH 2/2] # another method tried to read past EOF --- Corlib.Extensions/System/IO/Stream.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Corlib.Extensions/System/IO/Stream.cs b/Corlib.Extensions/System/IO/Stream.cs index abfe6665..21c53ca3 100644 --- a/Corlib.Extensions/System/IO/Stream.cs +++ b/Corlib.Extensions/System/IO/Stream.cs @@ -1188,7 +1188,7 @@ public static void ReadBytes(this Stream @this, long position, byte[] buffer, Se /// A awaitable Task representing the operation [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Task ReadBytesAsync(this Stream @this, long position, byte[] buffer, SeekOrigin seekOrigin = SeekOrigin.Begin) - => ReadBytesAsync(@this, position, buffer, 0, buffer.Length, seekOrigin); + => ReadBytesAsync(@this, position, buffer, 0, (int)Math.Min(buffer.Length, @this.Length - position), seekOrigin); /// /// Reads async Bytes from a given position with a given SeekOrigin in the given buffer with an offset