зеркало из https://github.com/github/codeql.git
Merge pull request #13928 from asgerf/js/ignore-huge-files
JS: Ignore files larger than 10 MB during extraction
This commit is contained in:
Коммит
d146514275
|
@ -222,6 +222,7 @@ public class AutoBuild {
|
||||||
private boolean installDependencies = false;
|
private boolean installDependencies = false;
|
||||||
private final VirtualSourceRoot virtualSourceRoot;
|
private final VirtualSourceRoot virtualSourceRoot;
|
||||||
private ExtractorState state;
|
private ExtractorState state;
|
||||||
|
private final long maximumFileSizeInMegabytes;
|
||||||
|
|
||||||
/** The default timeout when installing dependencies, in milliseconds. */
|
/** The default timeout when installing dependencies, in milliseconds. */
|
||||||
public static final int INSTALL_DEPENDENCIES_DEFAULT_TIMEOUT = 10 * 60 * 1000; // 10 minutes
|
public static final int INSTALL_DEPENDENCIES_DEFAULT_TIMEOUT = 10 * 60 * 1000; // 10 minutes
|
||||||
|
@ -236,6 +237,7 @@ public class AutoBuild {
|
||||||
this.defaultEncoding = getEnvVar("LGTM_INDEX_DEFAULT_ENCODING");
|
this.defaultEncoding = getEnvVar("LGTM_INDEX_DEFAULT_ENCODING");
|
||||||
this.installDependencies = Boolean.valueOf(getEnvVar("LGTM_INDEX_TYPESCRIPT_INSTALL_DEPS"));
|
this.installDependencies = Boolean.valueOf(getEnvVar("LGTM_INDEX_TYPESCRIPT_INSTALL_DEPS"));
|
||||||
this.virtualSourceRoot = makeVirtualSourceRoot();
|
this.virtualSourceRoot = makeVirtualSourceRoot();
|
||||||
|
this.maximumFileSizeInMegabytes = EnvironmentVariables.getMegabyteCountFromPrefixedEnv("MAX_FILE_SIZE", 10);
|
||||||
setupFileTypes();
|
setupFileTypes();
|
||||||
setupXmlMode();
|
setupXmlMode();
|
||||||
setupMatchers();
|
setupMatchers();
|
||||||
|
@ -1229,6 +1231,11 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
|
||||||
warn("Skipping " + file + ", which does not exist.");
|
warn("Skipping " + file + ", which does not exist.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
long fileSize = f.length();
|
||||||
|
if (fileSize > 1_000_000L * this.maximumFileSizeInMegabytes) {
|
||||||
|
warn("Skipping " + file + " because it is too large (" + StringUtil.printFloat(fileSize / 1_000_000.0) + " MB). The limit is " + this.maximumFileSizeInMegabytes + " MB.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
long start = logBeginProcess("Extracting " + file);
|
long start = logBeginProcess("Extracting " + file);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.semmle.js.extractor;
|
package com.semmle.js.extractor;
|
||||||
|
|
||||||
|
import com.semmle.util.data.UnitParser;
|
||||||
import com.semmle.util.exception.UserError;
|
import com.semmle.util.exception.UserError;
|
||||||
import com.semmle.util.process.Env;
|
import com.semmle.util.process.Env;
|
||||||
import com.semmle.util.process.Env.Var;
|
import com.semmle.util.process.Env.Var;
|
||||||
|
@ -19,6 +20,36 @@ public class EnvironmentVariables {
|
||||||
|
|
||||||
public static final String CODEQL_DIST_ENV_VAR = "CODEQL_DIST";
|
public static final String CODEQL_DIST_ENV_VAR = "CODEQL_DIST";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a number of megabytes by reading an environment variable with the given suffix,
|
||||||
|
* or the default value if not set.
|
||||||
|
* <p>
|
||||||
|
* The following prefixes are tried:
|
||||||
|
* <code>CODEQL_EXTRACTOR_JAVASCRIPT_</code>,
|
||||||
|
* <code>LGTM_</code>,
|
||||||
|
* <code>SEMMLE_</code>.
|
||||||
|
*/
|
||||||
|
public static int getMegabyteCountFromPrefixedEnv(String suffix, int defaultValue) {
|
||||||
|
String envVar = "CODEQL_EXTRACTOR_JAVASCRIPT_" + suffix;
|
||||||
|
String value = Env.systemEnv().get(envVar);
|
||||||
|
if (value == null || value.length() == 0) {
|
||||||
|
envVar = "LGTM_" + suffix;
|
||||||
|
value = Env.systemEnv().get(envVar);
|
||||||
|
}
|
||||||
|
if (value == null || value.length() == 0) {
|
||||||
|
envVar = "SEMMLE_" + suffix;
|
||||||
|
value = Env.systemEnv().get(envVar);
|
||||||
|
}
|
||||||
|
if (value == null || value.length() == 0) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
Integer amount = UnitParser.parseOpt(value, UnitParser.MEGABYTES);
|
||||||
|
if (amount == null) {
|
||||||
|
throw new UserError("Invalid value for " + envVar + ": '" + value + "'");
|
||||||
|
}
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the extractor root based on the <code>CODEQL_EXTRACTOR_JAVASCRIPT_ROOT</code> or <code>
|
* Gets the extractor root based on the <code>CODEQL_EXTRACTOR_JAVASCRIPT_ROOT</code> or <code>
|
||||||
* SEMMLE_DIST</code> or environment variable, or <code>null</code> if neither is set.
|
* SEMMLE_DIST</code> or environment variable, or <code>null</code> if neither is set.
|
||||||
|
|
|
@ -273,23 +273,6 @@ public class TypeScriptParser {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getMegabyteCountFromPrefixedEnv(String suffix, int defaultValue) {
|
|
||||||
String envVar = "SEMMLE_" + suffix;
|
|
||||||
String value = Env.systemEnv().get(envVar);
|
|
||||||
if (value == null || value.length() == 0) {
|
|
||||||
envVar = "LGTM_" + suffix;
|
|
||||||
value = Env.systemEnv().get(envVar);
|
|
||||||
}
|
|
||||||
if (value == null || value.length() == 0) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
Integer amount = UnitParser.parseOpt(value, UnitParser.MEGABYTES);
|
|
||||||
if (amount == null) {
|
|
||||||
throw new UserError("Invalid value for " + envVar + ": '" + value + "'");
|
|
||||||
}
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Start the Node.js parser wrapper process. */
|
/** Start the Node.js parser wrapper process. */
|
||||||
private void setupParserWrapper() {
|
private void setupParserWrapper() {
|
||||||
verifyNodeInstallation();
|
verifyNodeInstallation();
|
||||||
|
@ -297,8 +280,8 @@ public class TypeScriptParser {
|
||||||
int mainMemoryMb =
|
int mainMemoryMb =
|
||||||
typescriptRam != 0
|
typescriptRam != 0
|
||||||
? typescriptRam
|
? typescriptRam
|
||||||
: getMegabyteCountFromPrefixedEnv(TYPESCRIPT_RAM_SUFFIX, 2000);
|
: EnvironmentVariables.getMegabyteCountFromPrefixedEnv(TYPESCRIPT_RAM_SUFFIX, 2000);
|
||||||
int reserveMemoryMb = getMegabyteCountFromPrefixedEnv(TYPESCRIPT_RAM_RESERVE_SUFFIX, 400);
|
int reserveMemoryMb = EnvironmentVariables.getMegabyteCountFromPrefixedEnv(TYPESCRIPT_RAM_RESERVE_SUFFIX, 400);
|
||||||
|
|
||||||
System.out.println("Memory for TypeScript process: " + mainMemoryMb + " MB, and " + reserveMemoryMb + " MB reserve");
|
System.out.println("Memory for TypeScript process: " + mainMemoryMb + " MB, and " + reserveMemoryMb + " MB reserve");
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
category: minorAnalysis
|
||||||
|
---
|
||||||
|
* Files larger than 10 MB are no longer be extracted or analyzed.
|
Загрузка…
Ссылка в новой задаче