java-topology/defects/exposed/patch/exposed-0003-Table-clone-consParamNames.patch

15 lines
1.1 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UNDF: UNDF-2026-000000068
--- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/v1/core/Table.kt
+++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/v1/core/Table.kt
@@ -1682,8 +1682,10 @@ open class Table(
private fun <T : Any> T.clone(replaceArgs: Map<KProperty1<T, *>, Any> = emptyMap()): T = javaClass.kotlin.run {
val consParams = primaryConstructor!!.parameters
val mutableProperties = memberProperties.filterIsInstance<KMutableProperty1<T, Any?>>()
+ // CWE-407 fix: pre-compute constructor parameter names as HashSet to avoid O(P×C) repeated List allocations
+ val consParamNames = consParams.mapTo(HashSet()) { it.name }
val allValues = memberProperties
- .filter { it in mutableProperties || it.name in consParams.map(KParameter::name) }
+ .filter { it in mutableProperties || it.name in consParamNames }
.associate { it.name to (replaceArgs[it] ?: it.get(this@clone)) }
primaryConstructor!!.callBy(consParams.associateWith { allValues[it.name] }).also { newInstance ->
for (prop in mutableProperties) {