PrimitiveArray<T>.Values typically fails with ArgumentOutOfRangeException
- Dominant language
- C#
- Stars
- 39
- Forks
- 30
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 16
Description
### Describe the bug, including details regarding any error messages, version, and platform.
This property is currently implemented in PrimitiveArray.cs as
```C#
Values => ValueBuffer.Span.CastTo().Slice(Offset, Length);
```
but throws when T is larger than a byte because the order of `CastTo()` and `Slice()` is reversed. It should be
```
Values => ValueBuffer.Span.Slice(Offset, Length).CastTo();
```
The reason for this is `Length` ends up being the size of the underlying `ArrowBuffer`'s `Memory`. So, if `T` is larger than `byte`, `Slice()` is very likely to refuse to overrun the end of the buffer because preceding it with `CastTo()` means the `Span`'s length is no longer measured in bytes.
I haven't verified all of them but this should affect the derived classes `DoubleArray`, `FloatArray`, `Int16Array`, `Int32Array`, `Int64Array`, `UInt16Array`, `UInt32Array`, and `UInt64Array`. I've confirmed `UInt8Array.Values` works as expected, which should also be the case for `Int8Array`.
Contributor guide
Research direction
Start in PrimitiveArray.cs at the Values property and compare the current CastTo() and Slice(Offset, Length) order with the reported behavior. Verify Values for the listed numeric array types, especially types larger than byte, and confirm the ArgumentOutOfRangeException no longer occurs while UInt8Array and Int8Array remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- data
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100