fix: base64DecodeBytes unsigned byte values + improve JMH benchmark config#705
Draft
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Draft
fix: base64DecodeBytes unsigned byte values + improve JMH benchmark config#705He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
This was referenced Apr 6, 2026
0152957 to
bb5274e
Compare
…onfig Fix std.base64DecodeBytes to correctly return unsigned byte values (0-255) instead of signed Java byte values (-128..127). Java's byte type is signed, so without masking with 0xff, bytes >= 128 (e.g., 0x80 = 128) would appear as negative numbers (e.g., -128), violating the Jsonnet specification. Also increase JMH RegressionBenchmark iterations from 1 to 3 for both warmup and measurement phases, providing more stable and reliable benchmark results with proper confidence intervals. Changes: - EncodingModule.scala: Apply `& 0xff` mask in base64DecodeBytes to convert signed Java bytes to unsigned integers, matching Jsonnet byte semantics - RegressionBenchmark.scala: Increase warmup/measurement iterations to 3 - Add regression test: base64DecodeBytes_unsigned.jsonnet with boundary values (0, 127, 128, 255) and encode/decode round-trip verification Upstream reference: jit branch commits b833428, af4832f
bb5274e to
d1c2cb4
Compare
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.
Motivation
std.base64DecodeByteswas returning signed Java byte values (-128..127) instead of the Jsonnet-standard unsigned range (0..255). Bytes with the high bit set (≥128) were returned as negative numbers, violating the specification.Key Design Decision
Apply
& 0xffmask to convert signed Java bytes to unsigned integers, matching the Jsonnet specification and behavior of the C++, Go, and Rust implementations.Modification
sjsonnet/src/sjsonnet/stdlib/EncodingModule.scala(base64DecodeBytes):& 0xffmask:decoded(i) & 0xffconverts signed byte (-128..127) to unsigned int (0..255)Test:
new_test_suite/base64DecodeBytes_unsigned.jsonnet— verifies bytes ≥ 128 are returned as unsigned (e.g., 0xff → 255, not -1)Benchmark Results
This is a correctness fix, not a performance optimization. No benchmark impact expected.
Analysis
bytetype is signed (-128..127).Base64.getDecoder.decode()returnsbyte[]. Without masking, values ≥ 128 are negative.[0, 255]range.References
bytetype: signed, -128 to 127& 0xffmask: standard Java idiom for unsigned byte conversionResult
Fixes
std.base64DecodeBytesto return unsigned byte values (0-255) per the Jsonnet specification.