From 87f680683df1aec0a3f62f9adbd5b32fa9a6b5c9 Mon Sep 17 00:00:00 2001 From: Alexander Brandes Date: Mon, 26 Sep 2022 23:45:06 +0200 Subject: [PATCH] Update Upstream 0ef38b5 Use SnakeYaml 1.32+, set loader code point limit. (2194) Defaults to 64MB, can be set via -Dworldedit.yaml.codePointLimit sysprop. --- worldedit-core/build.gradle.kts | 2 +- .../com/sk89q/util/yaml/YAMLProcessor.java | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/worldedit-core/build.gradle.kts b/worldedit-core/build.gradle.kts index 944b44fa2..a5d40bb13 100644 --- a/worldedit-core/build.gradle.kts +++ b/worldedit-core/build.gradle.kts @@ -12,7 +12,7 @@ applyPlatformAndCoreConfiguration() dependencies { constraints { implementation("org.yaml:snakeyaml") { - version { strictly("1.30") } + version { strictly("1.33") } because("Bukkit provides SnakeYaml") } } diff --git a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java index cc7f2d937..dd65adab1 100644 --- a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java +++ b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java @@ -21,6 +21,7 @@ package com.sk89q.util.yaml; import com.sk89q.util.StringUtil; import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.SafeConstructor; import org.yaml.snakeyaml.nodes.Tag; @@ -89,13 +90,22 @@ public class YAMLProcessor extends YAMLNode { super(new LinkedHashMap<>(), writeDefaults); this.format = format; - DumperOptions options = new DumperOptions(); - options.setIndent(4); - options.setDefaultFlowStyle(format.getStyle()); + DumperOptions dumperOptions = new DumperOptions(); + dumperOptions.setIndent(4); + dumperOptions.setDefaultFlowStyle(format.getStyle()); Representer representer = new FancyRepresenter(); representer.setDefaultFlowStyle(format.getStyle()); - yaml = new Yaml(new SafeConstructor(), representer, options); + LoaderOptions loaderOptions = new LoaderOptions(); + try { + // 64 MB default + int yamlCodePointLimit = Integer.getInteger("worldedit.yaml.codePointLimit", 64 * 1024 * 1024); + loaderOptions.setCodePointLimit(yamlCodePointLimit); + } catch (NoSuchMethodError ignored) { + // pre-1.32 snakeyaml + } + + yaml = new Yaml(new SafeConstructor(), representer, dumperOptions, loaderOptions); this.file = file; }