Skip to content

GH-709: Correct length calculation of value buffers of variable-sized arrays - #707

Merged
lidavidm merged 1 commit into
apache:mainfrom
datadobi:issue_74
Apr 14, 2025
Merged

GH-709: Correct length calculation of value buffers of variable-sized arrays#707
lidavidm merged 1 commit into
apache:mainfrom
datadobi:issue_74

Conversation

@pepijnve

@pepijnvepepijnve commented Apr 10, 2025

Copy link
Copy Markdown
Contributor

What's Changed

For variable-size binary layout arrays, BufferImportTypeVisitor currently derives the length of the value buffer by calculating the difference between the last and first offset. When the first offset is not zero, this is actually incorrect and leads to out of bounds errors when attempting to read values from the imported array.

Instead, BufferImportTypeVisitor should simply use the last offset value as the length of the value buffer. This PR makes that change.

Just FYI, I bumped into this issue when attempting to import an array originating from DataFusion. A test query of the form SELECT column1 FROM VALUES ('a'), ('b'), ('c'), ('d') LIMIT 2 OFFSET 1; returns a slice of the full set of values. The values buffer contains all the original values, and the offsets buffer contains 1 and 2 as values to handle the offset from the query.

Closes#709 .

@github-actions

This comment has been minimized.

@pepijnve

Copy link
Copy Markdown
ContributorAuthor

This PR should have the 'bug-fix' label, but I don't seem to be able to apply that myself.

@lidavidmlidavidm added the bug-fix PRs that fix a big. label Apr 10, 2025
@github-actionsgithub-actionsBot added this to the 18.3.0 milestone Apr 10, 2025
@lidavidm

Copy link
Copy Markdown
Member

arrow-java doesn't support slicing in general, so for offset-based arrays, other code downstream may not work properly if the first offset is nonzero. I think the longer term fix is to either detect this and copy or decide to properly implement slicing. That said fixing an out-of-bounds is always good.

@lidavidmlidavidm 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.

LGTM.

Do you mind opening a new issue to link this PR to? The original issue has more discussion. In particular I think the cross-language integration tests need to be improved to cover this case

@pepijnvepepijnve changed the title GH-74: Correct length calculation of value buffers of variable-sized arraysGH-709: Correct length calculation of value buffers of variable-sized arraysApr 11, 2025
@pepijnve

Copy link
Copy Markdown
ContributorAuthor

I've created a new issue and update the summary and description of this PR.

@lidavidm

Copy link
Copy Markdown
Member

Thanks, the CI failures here should not be related but let me dig into what's going on - I may ask you to rebase

@lidavidm
lidavidm merged commit 74e8981 into apache:mainApr 14, 2025
dongjoon-hyun pushed a commit to apache/spark that referenced this pull request May 15, 2025
### What changes were proposed in this pull request?
This pr aims to upgrade `arrow-java` from 18.2.0 to 18.3.0.
### Why are the changes needed?
The new version bring some bug fixes, like:
- apache/arrow-java#627
- apache/arrow-java#654
- apache/arrow-java#656
- apache/arrow-java#693
- apache/arrow-java#705
- apache/arrow-java#707
- apache/arrow-java#722
In addition, the new version introduces a cascading upgrade for flatbuffers-java([ from 24.3.25 to 25.1.24 ](apache/arrow-java#600))
the full release note as follows:
- https://github.com/apache/arrow-java/releases/tag/v18.3.0
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
- Pass GitHub Acitons
### Was this patch authored or co-authored using generative AI tooling?
No
Closes#50892 from LuciferYang/arrow-java-18.3.0.
Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
timhurskidremio pushed a commit to timhurskidremio/dremio-arrow-java that referenced this pull request Dec 5, 2025
…-sized arrays (apache#707)
## What's Changed
For variable-size binary layout arrays, BufferImportTypeVisitor
currently derives the length of the value buffer by calculating the
difference between the last and first offset. When the first offset is
not zero, this is actually incorrect and leads to out of bounds errors
when attempting to read values from the imported array.
Instead, BufferImportTypeVisitor should simply use the last offset value
as the length of the value buffer. This PR makes that change.
Just FYI, I bumped into this issue when attempting to import an array
originating from DataFusion. A test query of the form `SELECT column1
FROM VALUES ('a'), ('b'), ('c'), ('d') LIMIT 2 OFFSET 1;` returns a
slice of the full set of values. The values buffer contains all the
original values, and the offsets buffer contains 1 and 2 as values to
handle the offset from the query.
Closesapache#709.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fixPRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessing values from imported 'C data interface' array can result in out of bounds reads

2 participants

@pepijnve@lidavidm