privacy-scan: a partial upstream path in a container's compressed bytes is left to the full check of the unpacked file
This commit is contained in:
parent
f7637d4940
commit
97c4640ca1
1 changed files with 20 additions and 11 deletions
|
|
@ -222,18 +222,27 @@ export function scanPath(path: string, terms: Term[], shown = basename(path), re
|
|||
report.files++;
|
||||
report.bytes += data.length;
|
||||
// the file's own bytes (names, uncompressed parts), then what is inside a container
|
||||
report.hits.push(...scanBuffer(shown, data, terms));
|
||||
const own = scanBuffer(shown, data, terms);
|
||||
const kind = kindOf(path, data.subarray(0, 1 << 20));
|
||||
if (kind !== 'file' && kind !== 'dir') {
|
||||
let u: { dir: string; cleanup: () => void } | null = null;
|
||||
try {
|
||||
u = unpack(path, kind);
|
||||
scanPath(u.dir, terms, `${shown}!`, report);
|
||||
} catch (e) {
|
||||
report.errors.push((e as Error).message);
|
||||
} finally {
|
||||
u?.cleanup();
|
||||
}
|
||||
if (kind === 'file' || kind === 'dir') { report.hits.push(...own); return report; }
|
||||
let u: { dir: string; cleanup: () => void };
|
||||
try {
|
||||
u = unpack(path, kind);
|
||||
} catch (e) {
|
||||
report.hits.push(...own);
|
||||
report.errors.push((e as Error).message);
|
||||
return report;
|
||||
}
|
||||
try {
|
||||
// An upstream path seen only in part in the compressed bytes (the rest is a back-reference) is checked in full
|
||||
// in the unpacked file, so the partial match in the container's own bytes is left to that check.
|
||||
report.hits.push(...own.filter(h => !(h.encoding === 'utf8' && h.what.startsWith('home folder')
|
||||
&& UPSTREAM_PATHS.some(p => data.toString('latin1', h.offset, h.offset + 64).startsWith(p.split('/').slice(0, 3).join('/') + '/')))));
|
||||
scanPath(u.dir, terms, `${shown}!`, report);
|
||||
} catch (e) {
|
||||
report.errors.push((e as Error).message);
|
||||
} finally {
|
||||
u.cleanup();
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue