This is an automated email from the ASF dual-hosted git repository.
HyukjinKwon pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new a58ea6662bde [SPARK-57653][CORE] Make UTF8String.getByte honor its
documented out-of-bounds contract
a58ea6662bde is described below
commit a58ea6662bdeeebe5ccb4b6a5ccd17bcc856af51
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Wed Jun 24 19:41:19 2026 +0900
[SPARK-57653][CORE] Make UTF8String.getByte honor its documented
out-of-bounds contract
### What changes were proposed in this pull request?
`UTF8String.getByte(int)` is documented as *"If byte index is invalid,
returns 0"*, but the implementation performed an unchecked
`Platform.getByte(base, offset + byteIndex)`, returning adjacent/uninitialized
memory for out-of-range indices. This PR adds the bounds check so the method
honors its documented contract:
```java
public byte getByte(int byteIndex) {
if (byteIndex < 0 || byteIndex >= numBytes) {
return 0;
}
return Platform.getByte(base, offset + byteIndex);
}
```
### Why are the changes needed?
Under JDK 25 the out-of-bounds read returned non-zero adjacent memory,
making `UTF8StringSuite.testGetByte` fail with `expected: <0> but was: <47>` in
the **Maven (Scala 2.13, JDK 25)** scheduled build. The previous `0` was never
guaranteed — it depended on memory layout. The fix makes the behavior
deterministic across JDKs.
### Does this PR introduce any user-facing change?
No.
### How was this patch tested?
Existing `UTF8StringSuite` (including `testGetByte`).
**Before (failing on master, JDK 25):** `UTF8StringSuite.testGetByte` —
`expected: <0> but was: <47>`
https://github.com/apache/spark/actions/runs/28035606804/job/82996960386
**After (this fix, JDK 25):** `UTF8StringSuite` — *Tests: succeeded 34,
failed 0*; `testGetByte` passes
https://github.com/HyukjinKwon/spark/actions/runs/28065895861/job/83089981477
This pull request and its description were written by Isaac.
Closes #56723 from HyukjinKwon/ci-fix/utf8-getbyte-jdk25.
Authored-by: Hyukjin Kwon <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
(cherry picked from commit faebce8be923ac9d375ca454f4aa9a634d11da9e)
Signed-off-by: Hyukjin Kwon <[email protected]>
---
.../unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java | 3 +++
1 file changed, 3 insertions(+)
diff --git
a/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
b/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
index c9256b0a8f33..f8d704193390 100644
--- a/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
+++ b/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
@@ -703,6 +703,9 @@ public final class UTF8String implements
Comparable<UTF8String>, Externalizable,
* Returns the byte at (byte) position `byteIndex`. If byte index is
invalid, returns 0.
*/
public byte getByte(int byteIndex) {
+ if (byteIndex < 0 || byteIndex >= numBytes) {
+ return 0;
+ }
return Platform.getByte(base, offset + byteIndex);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]