Skip to content

GH-1098: [Java][Vector] Fix always-true precondition check in LargeListVector.setValueCount#1097

Closed
LuciferYang wants to merge 1 commit intoapache:mainfrom
LuciferYang:fix/large-list-vector-precondition-logic
Closed

GH-1098: [Java][Vector] Fix always-true precondition check in LargeListVector.setValueCount#1097
LuciferYang wants to merge 1 commit intoapache:mainfrom
LuciferYang:fix/large-list-vector-precondition-logic

Conversation

@LuciferYang
Copy link
Copy Markdown

@LuciferYang LuciferYang commented Mar 30, 2026

What's Changed

Fix the precondition check in LargeListVector.setValueCount() where || made the condition always true (childValueCount <= Integer.MAX_VALUE || childValueCount >= Integer.MIN_VALUE is a tautology for any long value), allowing silent data corruption when childValueCount exceeds Integer.MAX_VALUE or is negative.

Changes:

  • Replace || with && and Integer.MIN_VALUE with 0 to correctly bound childValueCount to [0, Integer.MAX_VALUE], consistent with LargeListViewVector
  • Add rejection tests for negative and overflow childValueCount
  • Add positive boundary tests for zero, valid, and Integer.MAX_VALUE values

Closes #1098.

The precondition in LargeListVector.setValueCount() used `||` (logical OR)
instead of `&&` (logical AND), making the check always evaluate to true.
This meant childValueCount values exceeding Integer.MAX_VALUE or negative
values would silently pass the check, leading to data truncation when
cast to int on the next line.

Changed `childValueCount <= Integer.MAX_VALUE || childValueCount >= Integer.MIN_VALUE`
to `childValueCount <= Integer.MAX_VALUE && childValueCount >= 0`, consistent
with the correct implementation in LargeListViewVector (line 888).

Added two regression tests to verify the precondition rejects both negative
and overflow childValueCount values.
@LuciferYang LuciferYang changed the title fix: Fix always-true precondition check in LargeListVector.setValueCount GH-1098: [Java][Vector] Fix always-true precondition check in LargeListVector.setValueCount Mar 30, 2026
@github-actions
Copy link
Copy Markdown

Thank you for opening a pull request!

Please label the PR with one or more of:

  • bug-fix
  • chore
  • dependencies
  • documentation
  • enhancement

Also, add the 'breaking-change' label if appropriate.

See CONTRIBUTING.md for details.

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.

[Java][Vector] Always-true precondition check in LargeListVector.setValueCount allows silent data corruption

1 participant