pedrobtz opened a new pull request, #990: URL: https://github.com/apache/arrow-nanoarrow/pull/990
#946 fixed `ArrowArrayViewValidate()` reading offsets buffers through aligned pointers (#945). Validation still does the same in three other places: - run ends, through `ArrowArrayViewGetIntUnsafe()`, in default validation (first and last run end) and full validation (the increasing check); - list view and large list view offsets and sizes, through `data.as_int32[i]` and `data.as_int64[i]`, in full validation; - dictionary indices, through `ArrowArrayViewGetIntUnsafe()`, in full validation's range check. Each is a misaligned load when the buffer isn't aligned to the element width. That is undefined behaviour, and UBSan reports it, for input the C Data interface allows. This adds a static `ArrowArrayViewGetIntUnaligned()` to `array.c`. It reads the 16-, 32- and 64-bit integer types with `memcpy` and falls back to `ArrowArrayViewGetIntUnsafe()` for the others. The run-end and dictionary-index sites use it. The list view sites use `ArrowBufferViewGetInt32Unsafe()` and `ArrowBufferViewGetInt64Unsafe()` from #946. The new `ArrayViewTestValidateFullUnalignedIntegers` test validates, at the full level, a dictionary-encoded int32 view with indices at an odd address. It does the same for a run-end-encoded view with odd-addressed run ends, and for list view and large list view with odd-addressed offsets and sizes. Without the fix, UBSan reports the misaligned load (`inline_array.h:1160`). With it, `ctest` is clean under `UBSAN_OPTIONS=halt_on_error=1`. Found by fuzzing the IPC reader in the [zuarrow](https://github.com/pedrobtz/zuarrow) R package, which vendors nanoarrow. A pre-0.15 message whose body buffer starts at an odd offset reached the dictionary index check through `ArrowIpcArrayStreamReader`. The append and copy paths (`ArrowArrayAppendInt(dst, ArrowArrayViewGetIntUnsafe(src, i))`, the list view sizes in `ArrowArrayViewAppend...`, and run ends when slicing) read the same way. They are not validation, so they are left for a separate change. `ctest` passes in a plain Debug build and with ASan and UBSan with `halt_on_error=1` (410 tests each). The changed files are formatted with the pinned clang-format 16.0.6. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
