Skip to content

Commit a0e5247

Browse files
committed
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
1 parent 63428e3 commit a0e5247

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

ext/java/org/jruby/ext/psych/PsychParser.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.jcodings.unicode.UnicodeEncoding;
3535
import org.jruby.Ruby;
3636
import org.jruby.RubyArray;
37+
import org.jruby.RubyBoolean;
3738
import org.jruby.RubyClass;
3839
import org.jruby.RubyEncoding;
3940
import org.jruby.RubyFixnum;
@@ -488,6 +489,54 @@ public IRubyObject mark(ThreadContext context) {
488489
);
489490
}
490491

492+
@JRubyMethod(name = "max_aliases_for_collections=")
493+
public IRubyObject max_aliases_for_collections_set(IRubyObject max) {
494+
loadSettingsBuilder.setMaxAliasesForCollections(max.convertToInteger().getIntValue());
495+
496+
return max;
497+
}
498+
499+
@JRubyMethod(name = "max_aliases_for_collections")
500+
public IRubyObject max_aliases_for_collections(ThreadContext context) {
501+
return context.runtime.newFixnum(buildSettings().getMaxAliasesForCollections());
502+
}
503+
504+
@JRubyMethod(name = "allow_duplicate_keys=")
505+
public IRubyObject allow_duplicate_keys_set(IRubyObject allow) {
506+
loadSettingsBuilder.setAllowDuplicateKeys(allow.isTrue());
507+
508+
return allow;
509+
}
510+
511+
@JRubyMethod(name = "allow_duplicate_keys")
512+
public IRubyObject allow_duplicate_keys(ThreadContext context) {
513+
return RubyBoolean.newBoolean(context, buildSettings().getAllowDuplicateKeys());
514+
}
515+
516+
@JRubyMethod(name = "allow_recursive_keys=")
517+
public IRubyObject allow_recursive_keys_set(IRubyObject allow) {
518+
loadSettingsBuilder.setAllowRecursiveKeys(allow.isTrue());
519+
520+
return allow;
521+
}
522+
523+
@JRubyMethod(name = "allow_recursive_keys")
524+
public IRubyObject allow_recursive_keys(ThreadContext context) {
525+
return RubyBoolean.newBoolean(context, buildSettings().getAllowRecursiveKeys());
526+
}
527+
528+
@JRubyMethod(name = "code_point_limit=")
529+
public IRubyObject code_point_limit_set(IRubyObject limit) {
530+
loadSettingsBuilder.setCodePointLimit(limit.convertToInteger().getIntValue());
531+
532+
return limit;
533+
}
534+
535+
@JRubyMethod(name = "code_point_limit")
536+
public IRubyObject code_point_limit(ThreadContext context) {
537+
return context.runtime.newFixnum(buildSettings().getCodePointLimit());
538+
}
539+
491540
private LoadSettings buildSettings() {
492541
return loadSettingsBuilder.build();
493542
}

0 commit comments

Comments
 (0)