Skip to content

Commit 31e4b64

Browse files
authored
Fix DataFrame bounds checking on indexing elements (#6681)
1 parent c259a33 commit 31e4b64

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

src/Microsoft.Data.Analysis/DataFrameBuffer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ internal override T this[int index]
7777
{
7878
set
7979
{
80-
if (index > Length)
80+
if (index >= Length)
8181
throw new ArgumentOutOfRangeException(nameof(index));
82+
8283
RawSpan[index] = value;
8384
}
8485
}

src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected internal override Apache.Arrow.Array ToArrowArray(long startIndex, int
164164
{
165165
get
166166
{
167-
if (startIndex > Length)
167+
if (startIndex >= Length)
168168
{
169169
throw new ArgumentOutOfRangeException(nameof(startIndex));
170170
}
@@ -174,7 +174,7 @@ protected internal override Apache.Arrow.Array ToArrowArray(long startIndex, int
174174

175175
protected override IReadOnlyList<object> GetValues(long startIndex, int length)
176176
{
177-
if (startIndex > Length)
177+
if (startIndex >= Length)
178178
{
179179
throw new ArgumentOutOfRangeException(nameof(startIndex));
180180
}

src/Microsoft.Data.Analysis/ReadOnlyDataFrameBuffer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ internal virtual T this[int index]
6666
{
6767
get
6868
{
69-
if (index > Length)
69+
if (index >= Length)
7070
throw new ArgumentOutOfRangeException(nameof(index));
71+
7172
return ReadOnlySpan[index];
7273
}
7374
set => throw new NotSupportedException();

src/Microsoft.Data.Analysis/StringDataFrameColumn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void Append(string value)
7777

7878
private int GetBufferIndexContainingRowIndex(ref long rowIndex)
7979
{
80-
if (rowIndex > Length)
80+
if (rowIndex >= Length)
8181
{
8282
throw new ArgumentOutOfRangeException(Strings.ColumnIndexOutOfRange, nameof(rowIndex));
8383
}

src/Microsoft.Data.Analysis/VBufferDataFrameColumn.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ public void Append(VBuffer<T> value)
8585

8686
private int GetBufferIndexContainingRowIndex(ref long rowIndex)
8787
{
88-
if (rowIndex > Length)
88+
if (rowIndex >= Length)
8989
{
9090
throw new ArgumentOutOfRangeException(Strings.ColumnIndexOutOfRange, nameof(rowIndex));
9191
}
92+
9293
return (int)(rowIndex / int.MaxValue);
9394
}
9495

0 commit comments

Comments
 (0)