@@ -3,6 +3,7 @@ package com.github.codeql
33import com.github.codeql.utils.isExternalDeclaration
44import com.github.codeql.utils.isExternalFileClassMember
55import com.semmle.extractor.java.OdasaOutput
6+ import com.semmle.util.data.StringDigestor
67import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
78import org.jetbrains.kotlin.ir.declarations.*
89import org.jetbrains.kotlin.ir.util.isFileClass
@@ -44,7 +45,12 @@ class ExternalDeclExtractor(val logger: FileLogger, val invocationTrapFile: Stri
4445 val nextBatch = ArrayList (externalDeclWorkList)
4546 externalDeclWorkList.clear()
4647 nextBatch.forEach { workPair ->
47- val (irDecl, signature) = workPair
48+ val (irDecl, possiblyLongSignature) = workPair
49+ // In order to avoid excessively long signatures which can lead to trap file names longer than the filesystem
50+ // limit, we truncate and add a hash to preserve uniqueness if necessary.
51+ val signature = if (possiblyLongSignature.length > 100 ) {
52+ possiblyLongSignature.substring(0 , 92 ) + " #" + StringDigestor .digest(possiblyLongSignature).substring(0 , 8 )
53+ } else { possiblyLongSignature }
4854 output.getTrapLockerForDecl(irDecl, signature).useAC { locker ->
4955 locker.trapFileManager.useAC { manager ->
5056 val shortName = when (irDecl) {
@@ -73,6 +79,9 @@ class ExternalDeclExtractor(val logger: FileLogger, val invocationTrapFile: Stri
7379 val tw = TrapWriter (logger.loggerBase, TrapLabelManager (), trapFileBW, diagnosticTrapWriter)
7480 tw.writeComment(" Generated by the CodeQL Kotlin extractor for external dependencies" )
7581 tw.writeComment(" Part of invocation $invocationTrapFile " )
82+ if (signature != possiblyLongSignature) {
83+ tw.writeComment(" Function signature abbreviated; full signature is: $possiblyLongSignature " )
84+ }
7685 // Now elevate to a SourceFileTrapWriter, and populate the
7786 // file information if needed:
7887 val ftw = tw.makeFileTrapWriter(binaryPath, irDecl is IrClass )
0 commit comments