Truncate (but keep unique-ish) the names of very long file declarations

This commit is contained in:
Chris Smowton
2022-03-16 20:29:21 +00:00
committed by Ian Lynagh
parent b26044b327
commit 1b91a35df0

View File

@@ -2,6 +2,7 @@ package com.github.codeql
import com.github.codeql.utils.*
import com.semmle.extractor.java.OdasaOutput
import com.semmle.util.data.StringDigestor
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.common.lower.parentsWithSelf
import org.jetbrains.kotlin.backend.jvm.codegen.isRawType
@@ -257,7 +258,12 @@ open class KotlinUsesExtractor(
}
val paramTypes = parameters.map { useType(erase(it.type)) }
val signature = paramTypes.joinToString(separator = ",", prefix = "(", postfix = ")") { it.javaResult.signature!! }
val possiblyLongSignature = paramTypes.joinToString(separator = ",", prefix = "(", postfix = ")") { it.javaResult.signature!! }
// In order to avoid excessively long signatures which can lead to trap file names longer than the filesystem
// limit, we truncate and add a hash to preserve uniqueness if necessary.
val signature = if (possiblyLongSignature.length > 100) {
possiblyLongSignature.substring(0, 42) + "#" + StringDigestor.digest(possiblyLongSignature).substring(0, 8)
} else { possiblyLongSignature }
dependencyCollector?.addDependency(f, signature)
externalClassExtractor.extractLater(f, signature)
}