From a0e52470ede0bfe3cf629c6f8a6ca0c13c5face7 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 13 Jan 2023 08:48:44 -0600 Subject: Expose a few key LoadSettings values These values are often set to mitigate DOS attacks, so we want to expose them for JRuby users. See #579 --- ext/java/org/jruby/ext/psych/PsychParser.java | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/ext/java/org/jruby/ext/psych/PsychParser.java b/ext/java/org/jruby/ext/psych/PsychParser.java index fd5e19c..279b3d9 100644 --- a/ext/java/org/jruby/ext/psych/PsychParser.java +++ b/ext/java/org/jruby/ext/psych/PsychParser.java @@ -34,6 +34,7 @@ import org.jcodings.specific.UTF8Encoding; import org.jcodings.unicode.UnicodeEncoding; import org.jruby.Ruby; import org.jruby.RubyArray; +import org.jruby.RubyBoolean; import org.jruby.RubyClass; import org.jruby.RubyEncoding; import org.jruby.RubyFixnum; @@ -488,6 +489,54 @@ public class PsychParser extends RubyObject { ); } + @JRubyMethod(name = "max_aliases_for_collections=") + public IRubyObject max_aliases_for_collections_set(IRubyObject max) { + loadSettingsBuilder.setMaxAliasesForCollections(max.convertToInteger().getIntValue()); + + return max; + } + + @JRubyMethod(name = "max_aliases_for_collections") + public IRubyObject max_aliases_for_collections(ThreadContext context) { + return context.runtime.newFixnum(buildSettings().getMaxAliasesForCollections()); + } + + @JRubyMethod(name = "allow_duplicate_keys=") + public IRubyObject allow_duplicate_keys_set(IRubyObject allow) { + loadSettingsBuilder.setAllowDuplicateKeys(allow.isTrue()); + + return allow; + } + + @JRubyMethod(name = "allow_duplicate_keys") + public IRubyObject allow_duplicate_keys(ThreadContext context) { + return RubyBoolean.newBoolean(context, buildSettings().getAllowDuplicateKeys()); + } + + @JRubyMethod(name = "allow_recursive_keys=") + public IRubyObject allow_recursive_keys_set(IRubyObject allow) { + loadSettingsBuilder.setAllowRecursiveKeys(allow.isTrue()); + + return allow; + } + + @JRubyMethod(name = "allow_recursive_keys") + public IRubyObject allow_recursive_keys(ThreadContext context) { + return RubyBoolean.newBoolean(context, buildSettings().getAllowRecursiveKeys()); + } + + @JRubyMethod(name = "code_point_limit=") + public IRubyObject code_point_limit_set(IRubyObject limit) { + loadSettingsBuilder.setCodePointLimit(limit.convertToInteger().getIntValue()); + + return limit; + } + + @JRubyMethod(name = "code_point_limit") + public IRubyObject code_point_limit(ThreadContext context) { + return context.runtime.newFixnum(buildSettings().getCodePointLimit()); + } + private LoadSettings buildSettings() { return loadSettingsBuilder.build(); } -- cgit v1.2.1