Skip to content

Commit 241f977

Browse files
committed
fix that very large TypeScript files would crash the extractor
1 parent 8a22e22 commit 241f977

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,15 @@ private ExtractorConfig mkExtractorConfig() {
10101010
return config;
10111011
}
10121012

1013+
private boolean isFileTooLarge(Path f) {
1014+
long fileSize = f.toFile().length();
1015+
if (fileSize > 1_000_000L * this.maximumFileSizeInMegabytes) {
1016+
warn("Skipping " + f + " because it is too large (" + StringUtil.printFloat(fileSize / 1_000_000.0) + " MB). The limit is " + this.maximumFileSizeInMegabytes + " MB.");
1017+
return true;
1018+
}
1019+
return false;
1020+
}
1021+
10131022
private Set<Path> extractTypeScript(
10141023
Set<Path> files,
10151024
Set<Path> extractedFiles,
@@ -1051,9 +1060,13 @@ private Set<Path> extractTypeScript(
10511060
// compiler can parse them for us.
10521061
continue;
10531062
}
1054-
if (!extractedFiles.contains(sourcePath)) {
1055-
typeScriptFiles.add(sourcePath);
1063+
if (extractedFiles.contains(sourcePath)) {
1064+
continue;
1065+
}
1066+
if (isFileTooLarge(sourcePath)) {
1067+
continue;
10561068
}
1069+
typeScriptFiles.add(sourcePath);
10571070
}
10581071
typeScriptFiles.sort(PATH_ORDERING);
10591072
extractTypeScriptFiles(typeScriptFiles, extractedFiles, extractors);
@@ -1070,7 +1083,8 @@ private Set<Path> extractTypeScript(
10701083
List<Path> remainingTypeScriptFiles = new ArrayList<>();
10711084
for (Path f : files) {
10721085
if (!extractedFiles.contains(f)
1073-
&& extractors.fileType(f) == FileType.TYPESCRIPT) {
1086+
&& extractors.fileType(f) == FileType.TYPESCRIPT
1087+
&& !isFileTooLarge(f)) {
10741088
remainingTypeScriptFiles.add(f);
10751089
}
10761090
}
@@ -1236,9 +1250,7 @@ private void doExtract(FileExtractor extractor, Path file, ExtractorState state)
12361250
warn("Skipping " + file + ", which does not exist.");
12371251
return;
12381252
}
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.");
1253+
if (isFileTooLarge(file)) {
12421254
return;
12431255
}
12441256

0 commit comments

Comments
 (0)