Skip to content

Commit 92df0a3

Browse files
authored
Merge pull request #16546 from erik-krogh/ts-big-file-fix
JS: fix that very large TypeScript files would crash the extractor
2 parents a87ceed + a30bac1 commit 92df0a3

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ private CompletableFuture<?> extractSource() throws IOException {
735735
.collect(Collectors.toList());
736736

737737
filesToExtract = filesToExtract.stream()
738+
.filter(p -> !isFileTooLarge(p))
738739
.sorted(PATH_ORDERING)
739740
.collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
740741

@@ -1010,6 +1011,15 @@ private ExtractorConfig mkExtractorConfig() {
10101011
return config;
10111012
}
10121013

1014+
private boolean isFileTooLarge(Path f) {
1015+
long fileSize = f.toFile().length();
1016+
if (fileSize > 1_000_000L * this.maximumFileSizeInMegabytes) {
1017+
warn("Skipping " + f + " because it is too large (" + StringUtil.printFloat(fileSize / 1_000_000.0) + " MB). The limit is " + this.maximumFileSizeInMegabytes + " MB.");
1018+
return true;
1019+
}
1020+
return false;
1021+
}
1022+
10131023
private Set<Path> extractTypeScript(
10141024
Set<Path> files,
10151025
Set<Path> extractedFiles,
@@ -1051,9 +1061,10 @@ private Set<Path> extractTypeScript(
10511061
// compiler can parse them for us.
10521062
continue;
10531063
}
1054-
if (!extractedFiles.contains(sourcePath)) {
1055-
typeScriptFiles.add(sourcePath);
1064+
if (extractedFiles.contains(sourcePath)) {
1065+
continue;
10561066
}
1067+
typeScriptFiles.add(sourcePath);
10571068
}
10581069
typeScriptFiles.sort(PATH_ORDERING);
10591070
extractTypeScriptFiles(typeScriptFiles, extractedFiles, extractors);
@@ -1236,11 +1247,6 @@ private void doExtract(FileExtractor extractor, Path file, ExtractorState state)
12361247
warn("Skipping " + file + ", which does not exist.");
12371248
return;
12381249
}
1239-
long fileSize = f.length();
1240-
if (fileSize > 1_000_000L * this.maximumFileSizeInMegabytes) {
1241-
warn("Skipping " + file + " because it is too large (" + StringUtil.printFloat(fileSize / 1_000_000.0) + " MB). The limit is " + this.maximumFileSizeInMegabytes + " MB.");
1242-
return;
1243-
}
12441250

12451251
try {
12461252
long start = logBeginProcess("Extracting " + file);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* Fixed a bug where very large TypeScript files would cause database creation to crash. Large files over 10MB were already excluded from analysis, but the file size check was not applied to TypeScript files.

0 commit comments

Comments
 (0)