mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
Populate files table once per file, per trap file
Otherwise there's a chance the other trap file we're relying upon to populate the files table on our behalf gets overwritten (e.g. superceded by a newer .class file or more appropriate extractor) and we end up with a dangling reference. This adds only populating the tables when the label is new, to avoid emitting files entries every single time a generic class specialisation is mentioned.
This commit is contained in:
committed by
Ian Lynagh
parent
b35b74779a
commit
a740ead56d
@@ -11,6 +11,7 @@ import com.github.codeql.KotlinExtractorDbSchemeKt;
|
||||
import com.semmle.util.exception.CatastrophicError;
|
||||
import com.semmle.util.files.FileUtil;
|
||||
import com.semmle.util.trap.pathtransformers.PathTransformer;
|
||||
import kotlin.Unit;
|
||||
|
||||
public class PopulateFile {
|
||||
|
||||
@@ -78,14 +79,13 @@ public class PopulateFile {
|
||||
|
||||
public Label<DbFile> getFileLabel(File absoluteFile, boolean populateTables) {
|
||||
String databasePath = transformer.fileAsDatabaseString(absoluteFile);
|
||||
Label result = tw.getLabelFor("@\"" + escapeKey(databasePath) + ";sourcefile" + "\"");
|
||||
// Ensure the rewritten path is used from now on.
|
||||
|
||||
if(populateTables) {
|
||||
KotlinExtractorDbSchemeKt.writeFiles(tw, result, databasePath);
|
||||
populateParents(new File(databasePath), result);
|
||||
}
|
||||
|
||||
Label result = tw.<DbFile>getLabelFor("@\"" + escapeKey(databasePath) + ";sourcefile" + "\"", label -> {
|
||||
if(populateTables) {
|
||||
KotlinExtractorDbSchemeKt.writeFiles(tw, label, databasePath);
|
||||
populateParents(new File(databasePath), label);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,9 +146,6 @@ class KotlinExtractorGlobalState {
|
||||
val syntheticToRealClassMap = HashMap<IrClass, IrClass?>()
|
||||
val syntheticToRealFunctionMap = HashMap<IrSimpleFunction, IrSimpleFunction?>()
|
||||
val syntheticToRealFieldMap = HashMap<IrField, IrField?>()
|
||||
// This records source files (typically .class files) that have been extracted already, to save repeatedly extracting
|
||||
// the `files` and `folders` entry for a class file every time we see it.
|
||||
val extractedClassFilePaths = HashSet<String>()
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -134,13 +134,13 @@ open class KotlinUsesExtractor(
|
||||
|
||||
if (clsFile == null || isExternalDeclaration(cls)) {
|
||||
val filePath = getIrClassBinaryPath(cls)
|
||||
val newTrapWriter = tw.makeFileTrapWriter(filePath, globalExtensionState.extractedClassFilePaths.add(filePath))
|
||||
val newTrapWriter = tw.makeFileTrapWriter(filePath, true)
|
||||
val newLoggerTrapWriter = logger.tw.makeFileTrapWriter(filePath, false)
|
||||
val newLogger = FileLogger(logger.loggerBase, newLoggerTrapWriter)
|
||||
return KotlinFileExtractor(newLogger, newTrapWriter, filePath, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext, globalExtensionState)
|
||||
}
|
||||
|
||||
val newTrapWriter = tw.makeSourceFileTrapWriter(clsFile, false)
|
||||
val newTrapWriter = tw.makeSourceFileTrapWriter(clsFile, true)
|
||||
val newLoggerTrapWriter = logger.tw.makeSourceFileTrapWriter(clsFile, false)
|
||||
val newLogger = FileLogger(logger.loggerBase, newLoggerTrapWriter)
|
||||
return KotlinFileExtractor(newLogger, newTrapWriter, clsFile.path, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext, globalExtensionState)
|
||||
|
||||
Reference in New Issue
Block a user