Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit 1f258fe

Browse files
authored
Merge pull request #32 from matrix-org/michaelkaye/fix_removed_files
Make a copy of unencrypted files before scanning
2 parents c4cfb0d + 4784b64 commit 1f258fe

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/reporting.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,10 @@ async function generateReport(console, httpUrl, matrixFile, filePath, tempDir, s
258258
return reportCache[reportHash];
259259
}
260260

261-
// By default, the file is considered decrypted
262-
let decryptedFilePath = filePath;
261+
// Always make a decryptedFile on disk
262+
let decryptedFilePath = path.join(tempDir, 'unsafeDownloadedDecryptedFile');
263263

264264
if (matrixFile && matrixFile.key) {
265-
decryptedFilePath = path.join(tempDir, 'unsafeDownloadedDecryptedFile');
266265
console.info(`Decrypting ${filePath}, writing to ${decryptedFilePath}`);
267266

268267
try {
@@ -271,6 +270,13 @@ async function generateReport(console, httpUrl, matrixFile, filePath, tempDir, s
271270
console.error(err);
272271
throw new ClientError(400, 'Failed to decrypt file', 'MCS_MEDIA_FAILED_TO_DECRYPT');
273272
}
273+
} else {
274+
try {
275+
fs.copyFileSync(filePath, decryptedFilePath);
276+
} catch (err) {
277+
console.error(err);
278+
throw new ClientError(400, 'Failed to copy file for decryption', 'MCS_MEDIA_FAILED_TO_DECRYPT');
279+
}
274280
}
275281

276282
const cmd = script + ' ' + decryptedFilePath;

0 commit comments

Comments
 (0)