Skip to content

Commit d205699

Browse files
committed
fixed issue with large schema files in YAML
1 parent 094b533 commit d205699

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

core-parent/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
<properties>
1717
<!-- upgrading to 1.0.68 breaks Spring... TODO would need try upgrading in own branch -->
18-
<swagger.parser-v2.version>1.0.61</swagger.parser-v2.version>
18+
<swagger.parser-v2.version>1.0.64</swagger.parser-v2.version>
1919
<!-- upgrading to 2.1.18 breaks Spring... TODO would need try upgrading in own branch -->
20-
<swagger.parser-v3.version>2.1.8</swagger.parser-v3.version>
20+
<swagger.parser-v3.version>2.1.14</swagger.parser-v3.version>
2121
<swagger.annotations.version>2.2.7</swagger.annotations.version>
2222
</properties>
2323

core-tests/integration-tests/core-it/src/test/kotlin/org/evomaster/core/problem/rest/SamplerVerifierTest.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.evomaster.client.java.controller.api.dto.problem.param.DerivedParamCh
1313
import org.evomaster.client.java.controller.api.dto.problem.rpc.ScheduleTaskInvocationsDto
1414
import org.evomaster.client.java.controller.api.dto.problem.rpc.ScheduleTaskInvocationsResult
1515
import org.evomaster.core.BaseModule
16+
import org.evomaster.core.Main
1617
import org.evomaster.core.problem.rest.schema.RestSchema
1718
import org.evomaster.core.problem.rest.service.module.BlackBoxRestModule
1819
import org.evomaster.core.problem.rest.service.module.ResourceRestModule
@@ -28,10 +29,17 @@ import java.lang.reflect.InvocationTargetException
2829
import java.time.Duration
2930
import kotlin.io.path.Path
3031
import kotlin.sequences.filter
32+
import kotlin.text.contains
3133

3234

3335
class SamplerVerifierTest {
3436

37+
companion object {
38+
init {
39+
Main.applyGlobalJVMSettings()
40+
}
41+
}
42+
3543

3644
@Test
3745
fun testBase() {
@@ -272,7 +280,7 @@ class SamplerVerifierTest {
272280
|| (contains("visualstudio.com") && contains("v1"))
273281
|| (contains("youneedabudget.com") && contains("1.0.0"))
274282
|| (contains("zenoti.com") && contains("1.0.0")) // No actions for schema
275-
|| (contains("zoom.us") && contains("2.0.0")) // The incoming YAML document exceeds the limit: 3145728 code points.
283+
// || (contains("zoom.us") && contains("2.0.0")) // The incoming YAML document exceeds the limit: 3145728 code points.
276284
|| (contains("zuora.com") && contains("2021-08-20")) //The incoming YAML document exceeds the limit: 3145728 code points.
277285
}
278286
}

core/src/main/kotlin/org/evomaster/core/Main.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,26 @@ import kotlin.system.exitProcess
5454
class Main {
5555
companion object {
5656

57+
/**
58+
* Anything that impact whole JVM, needs to be done here, and called as first step in the main.
59+
* Note: this is done as a function because tests will usually not call Main, and might rely
60+
* on those settings for their behavior
61+
*/
62+
@JvmStatic
63+
fun applyGlobalJVMSettings(){
64+
Locale.setDefault(Locale.ENGLISH)
65+
//otherwise parser will crash on large OpenAPI schemas
66+
System.setProperty("maxYamlCodePoints", "" + (50 * 1024 * 1024))
67+
}
68+
5769
/**
5870
* Main entry point of the EvoMaster application
5971
*/
6072
@JvmStatic
6173
fun main(args: Array<String>) {
6274

6375
try {
64-
Locale.setDefault(Locale.ENGLISH)
76+
applyGlobalJVMSettings()
6577

6678
printLogo()
6779
printVersion()

core/src/main/kotlin/org/evomaster/core/problem/rest/schema/RestSchema.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package org.evomaster.core.problem.rest.schema
33
import com.fasterxml.jackson.databind.JsonNode
44
import com.fasterxml.jackson.databind.ObjectMapper
55
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
6+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder
67
import org.evomaster.core.remote.SutProblemException
8+
import org.yaml.snakeyaml.LoaderOptions
79

810

911
/**
@@ -62,7 +64,16 @@ class RestSchema(
6264

6365
//https://swagger.io/docs/specification/v3_0/using-ref/
6466

65-
val mapper = ObjectMapper(YAMLFactory())
67+
// snakeyaml has default limits on size, which are very low
68+
val yaml = YAMLFactoryBuilder(YAMLFactory())
69+
.loaderOptions(LoaderOptions().apply {
70+
codePointLimit = 50 * 1024 * 1024 // 50MB
71+
maxAliasesForCollections = 1000
72+
nestingDepthLimit = 100
73+
})
74+
.build()
75+
76+
val mapper = ObjectMapper(yaml)
6677
val tree = mapper.readTree(schema.schemaRaw)
6778
val refs = findAllSRef(tree)
6879

0 commit comments

Comments
 (0)