adamreeve opened a new issue, #43267:
URL: https://github.com/apache/arrow/issues/43267
### Describe the bug, including details regarding any error messages,
version, and platform.
Code to reproduce the problem as an XUnit test:
```c#
[Fact]
public unsafe void RoundTripArrayWithOffset()
{
Int32Array array = new Int32Array.Builder()
.AppendRange(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })
.Build();
IArrowArray sliced = array.Slice(2, 6);
CArrowArray* cArray = CArrowArray.Create();
CArrowArrayExporter.ExportArray(sliced, cArray);
using (var importedSlice =
(Int32Array)CArrowArrayImporter.ImportArray(cArray, array.Data.DataType))
{
Assert.Equal(6, importedSlice.Length); // OK
Assert.Equal(2, importedSlice.Offset); // OK
Assert.Equal(2, importedSlice.GetValue(0)); // Throws
}
CArrowArray.Free(cArray);
}
```
This throws:
```
System.ArgumentOutOfRangeException: Specified argument was out of the range
of valid values.
System.ArgumentOutOfRangeException
Specified argument was out of the range of valid values.
at Apache.Arrow.PrimitiveArray`1.get_Values() in
/home/adam/dev/arrow/csharp/src/Apache.Arrow/Arrays/PrimitiveArray.cs:line 34
at Apache.Arrow.Tests.CDataInterfaceDataTests.RoundTripArrayWithOffset()
in
/home/adam/dev/arrow/csharp/test/Apache.Arrow.Tests/CDataInterfaceDataTests.cs:line
83
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void**
arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj,
BindingFlags invokeAttr)
```
The problem is that when importing the buffers, we assume the buffer length
is at least `array.length * typeByteWidth` (see
[ImportFixedWidthBuffers](https://github.com/apache/arrow/blob/6845bb64e4e4da42b146ca5227db0a1c4ee33f94/csharp/src/Apache.Arrow/C/CArrowArrayImporter.cs#L393)),
but really it should be `(array.length + array.offset) * typeByteWidth`. This
example is for a fixed width array type, but other more complex array types
appear to have the same problem.
I don't have any immediate plans to fix this myself, but noticed this
problem as part of looking at #43266.
### Component(s)
C#
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]