Repository navigation
Conversation
sferik
force-pushed
the
java-as-json-symbol-recursion
branch
from
November 5, 2026 19:16
a62512c to
9227d68
Compare
When a string with invalid encoding is generated in strict mode, the Java and pure-Ruby generators call as_json on it. If as_json returned a Symbol, the Symbol was turned back into the same invalid string, so as_json was called again, forever. JRuby died with a StackOverflowError and TruffleRuby with a SystemStackError. Do what convert_invalid_encoding does in generator.c: if as_json returned something other than the original string, turn a Symbol into its String, and raise "source sequence is illegal/malformed utf-8" if that string is still invalid instead of trying again or transcoding it. The comparison happens before the Symbol is converted, because TruffleRuby's Symbol#name returns the same cached string each time. This lets test_json_coder_symbol_invalid_encoding run on JRuby and TruffleRuby. Part of ruby#1123
The JSON.load case in test_parse_duplicate_key with an on_load proc that returns a non-String key was skipped on JRuby, but it passes there now. Part of ruby#1123
sferik
force-pushed
the
java-as-json-symbol-recursion
branch
from
November 5, 2026 20:44
9227d68 to
71c93ce
Compare
This branch has not been deployed
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.
On JRuby,
JSON::Coderoverflows the stack when a string with invalid encoding goes toas_jsonandas_jsonreturns a Symbol:The Java generator turns the Symbol back into the same invalid string and calls
as_jsonon it again, forever.generator.ccallsas_jsononly once (as_json_calledingenerate_json_general, andconvert_invalid_encoding). It raises if a new string fromas_jsonis still invalid. This change does the same inStringHandler.The
RUBY_ENGINE == "ruby"guard on that part oftest_json_coder_symbol_invalid_encodingis gone, so the test now runs on JRuby. It fails there without the fix.A second commit removes the JRuby guard from the
JSON.loadcase intest_parse_duplicate_key, which already passes on JRuby.