[common] Fix ArrayIndexOutOfBoundsException in .toArray() methods#2158
Open
binary-signal wants to merge 4 commits intoapache:mainfrom
Open
[common] Fix ArrayIndexOutOfBoundsException in .toArray() methods#2158binary-signal wants to merge 4 commits intoapache:mainfrom
binary-signal wants to merge 4 commits intoapache:mainfrom
Conversation
Contributor
Author
|
@wuchong could you please have a look when you have time |
ecf12fd to
b1c70cc
Compare
array conversions
b1c70cc to
73d8682
Compare
Signed-off-by: binary-signal <binary-signal@github.noreply.com>
Contributor
Author
|
@fresh-borzoni @luoyuxia PTAL 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue: close #2157
Purpose
Fix incorrect
targetOffsetusage inBinaryArray’sto*Array()methods.Previously, these methods passed
UNSAFE.arrayBaseOffset(...)constants (e.g.,DOUBLE_ARRAY_OFFSET) toBinarySegmentUtils.copyToUnsafe(). These values represent raw memory offsets (typically ~16 bytes on 64-bit JVMs), whilecopyToUnsafe()expects a standard 0-based Java array index.This mismatch caused writes to start at an incorrect position in the target array, leading to:
ArrayIndexOutOfBoundsExceptionFor example, with a 20-element double array:
targetOffset ≈ 16target[16]totarget[35]Brief change log
BinaryArray.javaUNSAFE.arrayBaseOffset(...)constants with0for thetargetOffsetparameter in:toBooleanArraytoByteArraytoShortArraytoIntArraytoLongArraytoFloatArraytoDoubleArrayBinaryArrayTest.javaTests
Added the following round-trip tests:
testRoundTripToBooleanArraytestRoundTripToByteArraytestRoundTripToShortArraytestRoundTripToIntArraytestRoundTripToLongArraytestRoundTripToFloatArraytestRoundTripToDoubleArrayAPI & Compatibility