Skip to content

fix: Correctly subscript ViewArrayAsBytes, ViewArrayAsFixedSizeBytes and ViewBinaryViewArrayAsBytes with offset - #1016

Merged
paleolimbot merged 1 commit into
apache:mainfrom
shashank11yadav:fix/view-bytes-offset
Nov 16, 2026
Merged

paleolimbot merged 1 commit into
apache:mainfrom
shashank11yadav:fix/view-bytes-offset

Conversation

@shashank11yadav

Copy link
Copy Markdown
Contributor

Fixes #1015

What changed

  • operator[] in ViewArrayAsBytes, ViewBinaryViewArrayAsBytes and ViewArrayAsFixedSizeBytes (src/nanoarrow/hpp/view.hpp) now passes range_.offset + i to RandomAccessRange::get(), the same as ViewArrayAs<T>::operator[] already does.
  • Three regression tests in src/nanoarrow/hpp/view_test.cc, one per view. Each sets offset 2 and length 2 and checks view[0] and view[1] through both the ArrowArray and ArrowArrayView constructors. The BinaryView test uses a string longer than the inline size, so it also covers the variadic-buffer path.

Why

view[i] passed the logical index straight to RandomAccessRange::get(), which takes a physical index. On a sliced array (offset > 0), view[0] returned the first element of the underlying buffer instead of the first element of the slice. Iteration already respected the offset, so the two disagreed. This change does not add bounds checking to operator[].

How it was tested

  • Commit 20b37eb against upstream/main, Debug build with CMake:
    • cmake --build build followed by ctest -R "^NanoarrowHppTest": 15 of 15 tests pass.
    • ctest -R for the three new tests: 3 of 3 pass.
    • The same three tests without the fix: 3 of 3 fail.
    • git diff --check upstream/main: pass.
  • clang-format 16.0.6 (--dry-run --Werror) and codespell 2.2.5 on the changed files: clean. pre-commit run --all-files was not run.
  • Not run: the full CI matrix (Meson, release, shared and namespaced builds, bundled builds, valgrind, clang-tidy).

…ytes and ViewBinaryViewArrayAsBytes with offset

operator[] on these views passed the logical index straight to
RandomAccessRange::get(), which expects a physical index, so subscripting
a sliced array returned elements from the start of the buffer. Add the
range offset, as ViewArrayAs<T> already does.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.56%. Comparing base (ee22361) to head (20b37eb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1016   +/-   ##
=======================================
  Coverage   78.55%   78.56%           
=======================================
  Files         106      106           
  Lines       17297    17300    +3     
  Branches     2066     2066           
=======================================
+ Hits        13587    13591    +4     
  Misses       2446     2446           
+ Partials     1264     1263    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@paleolimbot paleolimbot changed the title fix(hpp): Correctly subscript ViewArrayAsBytes, ViewArrayAsFixedSizeBytes and ViewBinaryViewArrayAsBytes with offset fix: Correctly subscript ViewArrayAsBytes, ViewArrayAsFixedSizeBytes and ViewBinaryViewArrayAsBytes with offset Nov 16, 2026
@paleolimbot
paleolimbot merged commit f7cdcf3 into apache:main Nov 16, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ViewArrayAsBytes, ViewArrayAsFixedSizeBytes and ViewBinaryViewArrayAsBytes operator[] ignore the array offset

3 participants