Skip to content

Commit b0beba8

Browse files
mnonnenmachersschuberth
authored andcommitted
Set the code point limit for SnakeYAML to 1GB
Since version 1.32 [1] SnakeYAML sets the limit for incoming data to 3MB. Since Jackson 2.14 [2] it is possible to override this default, so hardcode the limit to 1GB to allow parsing large ORT result files. [1]: https://bitbucket.org/snakeyaml/snakeyaml/wiki/Changes [2]: FasterXML/jackson-dataformats-text#337 Signed-off-by: Martin Nonnenmacher <[email protected]>
1 parent b62b740 commit b0beba8

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

build.gradle.kts

-4
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,6 @@ subprojects {
244244
// Ensure that all transitive versions of Kotlin libraries match our version of Kotlin.
245245
force("org.jetbrains.kotlin:kotlin-reflect:${rootProject.libs.versions.kotlinPlugin.get()}")
246246
force("org.jetbrains.kotlin:kotlin-script-runtime:${rootProject.libs.versions.kotlinPlugin.get()}")
247-
248-
// Starting with version 1.32 the YAML file size is limited to 3 MiB, which is not configurable yet via
249-
// Hoplite or Jackson.
250-
force("org.yaml:snakeyaml:1.31")
251247
}
252248
}
253249
}

model/src/main/kotlin/Mappers.kt

+13-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ import com.fasterxml.jackson.databind.SerializationFeature
2626
import com.fasterxml.jackson.databind.json.JsonMapper
2727
import com.fasterxml.jackson.databind.node.MissingNode
2828
import com.fasterxml.jackson.dataformat.xml.XmlMapper
29+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
2930
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper
3031
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
3132
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
3233

34+
import org.yaml.snakeyaml.LoaderOptions
35+
3336
val PROPERTY_NAMING_STRATEGY = PropertyNamingStrategies.SNAKE_CASE as PropertyNamingStrategies.NamingBase
3437

3538
/**
@@ -46,6 +49,15 @@ val mapperConfig: ObjectMapper.() -> Unit = {
4649

4750
val jsonMapper = JsonMapper().apply(mapperConfig)
4851
val xmlMapper = XmlMapper().apply(mapperConfig)
49-
val yamlMapper = YAMLMapper().apply(mapperConfig)
52+
53+
private val loaderOptions = LoaderOptions().apply {
54+
// Set the code point limit to 1GB, required since SnakeYAML 1.32. Also see:
55+
// https://github.com/FasterXML/jackson-dataformats-text/tree/2.15/yaml#maximum-input-yaml-document-size-3-mb
56+
// https://github.com/FasterXML/jackson-dataformats-text/issues/337
57+
// TODO: Consider making this configurable.
58+
codePointLimit = 1024 * 1024 * 1024
59+
}
60+
private val yamlFactory = YAMLFactory.builder().loaderOptions(loaderOptions).build()
61+
val yamlMapper = YAMLMapper(yamlFactory).apply(mapperConfig)
5062

5163
val EMPTY_JSON_NODE: JsonNode = MissingNode.getInstance()

0 commit comments

Comments
 (0)