Add input validation for ReadBytesAsync count parameter

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-03 17:19:55 +00:00
parent 372ecb77d0
commit 77015224f6

View File

@@ -24,6 +24,16 @@ public static class BinaryReaderExtensions
CancellationToken cancellationToken = default
)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count), "Count must be non-negative.");
}
if (count == 0)
{
return Array.Empty<byte>();
}
// For small allocations, direct allocation is more efficient than pooling
// due to ArrayPool overhead and the need to copy data to return array
if (count <= 256)