Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public override long GetBytes(int i, long dataIndex, byte[]? buffer, int bufferI
cbytes = data.Length;

// since arrays can't handle 64 bit values and this interface doesn't
// allow chunked access to data, a dataIndex outside the rang of Int32
// allow chunked access to data, a dataIndex outside the range of Int32
// is invalid
if (dataIndex > int.MaxValue)
if ((ulong)dataIndex > int.MaxValue)
{
throw ADP.InvalidSourceBufferIndex(cbytes, dataIndex, nameof(dataIndex));
}
Expand Down Expand Up @@ -182,9 +182,9 @@ public override long GetChars(int i, long dataIndex, char[]? buffer, int bufferI
int cchars = data.Length;

// since arrays can't handle 64 bit values and this interface doesn't
// allow chunked access to data, a dataIndex outside the rang of Int32
// allow chunked access to data, a dataIndex outside the range of Int32
// is invalid
if (dataIndex > int.MaxValue)
if ((ulong)dataIndex > int.MaxValue)
{
throw ADP.InvalidSourceBufferIndex(cchars, dataIndex, nameof(dataIndex));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

namespace System.Data.Common.Tests
{
public class DataRecordInternalTest
{
[Fact]
public void GetBytes_NegativeDataIndex_ThrowsIndexOutOfRangeException()
{
DataTable table = new DataTable();
table.Columns.Add("Bytes", typeof(byte[]));
table.Rows.Add(new byte[] { 1, 2, 3 });

using DataTableReader reader = table.CreateDataReader();
reader.Read();

byte[] buffer = new byte[3];

Assert.Throws<IndexOutOfRangeException>(() => reader.GetBytes(0, Int64.MinValue, buffer, 0, buffer.Length));
}

[Fact]
public void GetChars_NegativeDataIndex_ThrowsIndexOutOfRangeException()
{
DataTable table = new DataTable();
table.Columns.Add("Chars", typeof(char[]));
table.Rows.Add(new char[] { 'a', 'b', 'c' });

using DataTableReader reader = table.CreateDataReader();
reader.Read();

char[] buffer = new char[3];

Assert.Throws<IndexOutOfRangeException>(() => reader.GetChars(0, Int64.MinValue, buffer, 0, buffer.Length));
}
}
}
Loading