Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the code point limit for SnakeYAML to 1GB #6124

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,6 @@ subprojects {
// Ensure that all transitive versions of Kotlin libraries match our version of Kotlin.
force("org.jetbrains.kotlin:kotlin-reflect:${rootProject.libs.versions.kotlinPlugin.get()}")
force("org.jetbrains.kotlin:kotlin-script-runtime:${rootProject.libs.versions.kotlinPlugin.get()}")

// Starting with version 1.32 the YAML file size is limited to 3 MiB, which is not configurable yet via
// Hoplite or Jackson.
force("org.yaml:snakeyaml:1.31")
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion model/src/main/kotlin/Mappers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.databind.node.MissingNode
import com.fasterxml.jackson.dataformat.xml.XmlMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.registerKotlinModule

import org.yaml.snakeyaml.LoaderOptions

val PROPERTY_NAMING_STRATEGY = PropertyNamingStrategies.SNAKE_CASE as PropertyNamingStrategies.NamingBase

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

val jsonMapper = JsonMapper().apply(mapperConfig)
val xmlMapper = XmlMapper().apply(mapperConfig)
val yamlMapper = YAMLMapper().apply(mapperConfig)

private val loaderOptions = LoaderOptions().apply {
// Set the code point limit to 1GB, required since SnakeYAML 1.32. Also see:
// https://github.com/FasterXML/jackson-dataformats-text/tree/2.15/yaml#maximum-input-yaml-document-size-3-mb
// https://github.com/FasterXML/jackson-dataformats-text/issues/337
// TODO: Consider making this configurable.
codePointLimit = 1024 * 1024 * 1024
}
private val yamlFactory = YAMLFactory.builder().loaderOptions(loaderOptions).build()
val yamlMapper = YAMLMapper(yamlFactory).apply(mapperConfig)

val EMPTY_JSON_NODE: JsonNode = MissingNode.getInstance()