From bc1cd58958c5b5be9aca2a785a045e2f918ab573 Mon Sep 17 00:00:00 2001 From: Joshua Klein Date: Sun, 1 Feb 2026 16:23:46 -0500 Subject: [PATCH 1/2] fix: switch to unsigned long integers for computing bit-length intermediate value when importing very big array via CData ABI --- src/Apache.Arrow/C/CArrowArrayImporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Apache.Arrow/C/CArrowArrayImporter.cs b/src/Apache.Arrow/C/CArrowArrayImporter.cs index c454380e..0c2add78 100644 --- a/src/Apache.Arrow/C/CArrowArrayImporter.cs +++ b/src/Apache.Arrow/C/CArrowArrayImporter.cs @@ -470,7 +470,7 @@ private ArrowBuffer[] ImportFixedWidthBuffers(CArrowArray* cArray, int bitWidth) int length = checked((int)cArray->offset + (int)cArray->length); int valuesLength; if (bitWidth >= 8) - valuesLength = checked(length * bitWidth / 8); + valuesLength = checked((int)((ulong)length * (ulong)bitWidth / 8ul)); else valuesLength = checked((int)BitUtility.RoundUpToMultipleOf8(length) / 8); From f64581e5a89e21fed01974e815e00afbf1b42183 Mon Sep 17 00:00:00 2001 From: Joshua Klein Date: Sun, 1 Feb 2026 23:17:29 -0500 Subject: [PATCH 2/2] Add debug assertion checking bitWidth is a multiple of 8 Co-authored-by: Adam Reeve --- src/Apache.Arrow/C/CArrowArrayImporter.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Apache.Arrow/C/CArrowArrayImporter.cs b/src/Apache.Arrow/C/CArrowArrayImporter.cs index 0c2add78..2dc4adba 100644 --- a/src/Apache.Arrow/C/CArrowArrayImporter.cs +++ b/src/Apache.Arrow/C/CArrowArrayImporter.cs @@ -470,7 +470,10 @@ private ArrowBuffer[] ImportFixedWidthBuffers(CArrowArray* cArray, int bitWidth) int length = checked((int)cArray->offset + (int)cArray->length); int valuesLength; if (bitWidth >= 8) + { + Debug.Assert(bitWidth % 8 == 0); valuesLength = checked((int)((ulong)length * (ulong)bitWidth / 8ul)); + } else valuesLength = checked((int)BitUtility.RoundUpToMultipleOf8(length) / 8);