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
…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
This was referenced Apr 6, 2026
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.base64DecodeBytesreturns incorrect values for bytes >= 128. Java'sbytetype is signed (-128..127), so decoding base64 data containing high bytes (e.g., 0x80 = 128) produces negative numbers instead of the expected unsigned values (0-255). This violates the Jsonnet specification.Additionally, the JMH
RegressionBenchmarkuses only 1 warmup and 1 measurement iteration, producing noisy results with wide confidence intervals that make it difficult to detect real performance changes.Key Design Decision
& 0xffto convert signed bytes to unsigned integers, consistent with the existingencodeUTF8implementation inStringModule.scalaModification
Bug Fix:
EncodingModule.scala& 0xffmask when converting decoded bytes toVal.Num, ensuring values are in the unsigned range 0-255.map()with explicit while-loop for consistency with other encoding functionsBenchmark Config:
RegressionBenchmark.scala@Warmup(iterations = 3, time = 2)(wasiterations = 1)@Measurement(iterations = 3)(wasiterations = 1)Regression Test:
base64DecodeBytes_unsigned.jsonnetbase64DecodeBytes(base64([0, 127, 128, 200, 255])) == [0, 127, 128, 200, 255]Benchmark Results
JMH (3 iterations, back-to-back runs)
No performance impact — this is a correctness fix. The base64DecodeBytes benchmark is unchanged within CI:
All confidence intervals overlap — no statistically significant change.
Analysis
The bug manifests when decoding base64 data containing bytes in the range 128-255. For example:
std.base64DecodeBytes("gIA=")should return[128, 128]but returned[-128, -128]std.base64DecodeBytes("/w==")should return[255]but returned[-1]The fix is the standard Java unsigned byte conversion:
byte & 0xffpromotes the signed byte to an int with zero-extension, producing the correct unsigned value.References
b833428e,af4832f2StringModule.scalaencodeUTF8:bytes(i) & 0xffResult