Skip to content

Commit 51cea14

Browse files
agustingrohfrancostramana
authored andcommitted
SP-679 Adds file size limit filter on local cryptography scanning
1 parent ee5698d commit 51cea14

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scanoss",
3-
"version": "0.12.1",
3+
"version": "0.12.2",
44
"description": "The SCANOSS JS package provides a simple, easy to consume module for interacting with SCANOSS APIs/Engine.",
55
"main": "build/main/index.js",
66
"typings": "build/main/index.d.ts",

Diff for: src/cli/commands/crypto.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function cryptoHandler(rootPath: string, options: any){
3535
console.log("Searching for local cryptography...")
3636
const results = await cryptoScanner.scan(fileList);
3737

38-
if(options.output) {
38+
if (options.output) {
3939
await fs.promises.writeFile(options.output, JSON.stringify(results, null, 2));
4040
console.log(`Results found in ${options.output}`);
4141
} else {

Diff for: src/sdk/Cryptography/CryptoProvider/LocalCrypto.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export class LocalCrypto {
1414

1515
private cryptoRules: Map<string, RegExp>;
1616

17+
private readonly MAX_FILE_SIZE = 2 * 1024 * 1024 * 1024;
18+
1719
/**
1820
* Constructs a new LocalCrypto.
1921
* @param cryptoRules An array of CryptoAlgorithmRules used to create the search rules.
@@ -30,9 +32,11 @@ export class LocalCrypto {
3032
public async search(files: Array<string>): Promise<Array<CryptoItem>> {
3133
if (files.length <= 0) return [];
3234
const cryptoItems = files.map((f)=> { return new CryptoItem(f) });
33-
await Promise.all(cryptoItems.map(async (c) => {
35+
36+
for(let c of cryptoItems) {
3437
await this.searchCrypto(c);
35-
}));
38+
}
39+
3640
return cryptoItems;
3741
}
3842

@@ -43,7 +47,12 @@ export class LocalCrypto {
4347
*/
4448
private async searchCrypto(cryptoItem: CryptoItem){
4549
const cryptoFound = new Array<string>();
46-
let content = await fs.promises.readFile(cryptoItem.getPath(), 'utf-8');
50+
const stats = await fs.promises.stat(cryptoItem.getPath());
51+
if (stats.size > this.MAX_FILE_SIZE) {
52+
cryptoItem.setAlgorithms([]);
53+
return;
54+
}
55+
let content = await fs.promises.readFile(cryptoItem.getPath(), 'utf-8');
4756
this.cryptoRules.forEach((value, key) => {
4857
try {
4958
const matches = content.match(value);
@@ -54,10 +63,15 @@ export class LocalCrypto {
5463
console.error(e);
5564
}
5665
});
66+
// Release memory
67+
content = null;
5768
const results: Array<CryptoAlgorithm> = [];
5869
cryptoFound.forEach((cf)=>{
5970
results.push(this.cryptoMapper.get(cf));
6071
});
6172
cryptoItem.setAlgorithms(results);
6273
}
74+
6375
}
76+
77+

0 commit comments

Comments
 (0)