Skip to content

Check the saved file length + md5 hash at upload processing. #8728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 1, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/lib/package/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,19 @@ class PackageBackend {
_logger.info('Examining tarball content ($guid).');
final sw = Stopwatch()..start();
final file = File(filename);
final fileLength = await file.length();
if (fileLength != info.length) {
_logger.warning(
'Saved file length missmatch ($fileLength != ${info.length}).');
throw InvalidInputException(
'Failed to save uploaded file: length missmatch.');
}
final md5Hash = (await file.openRead().transform(md5).single).bytes;
if (!md5Hash.byteToByteEquals(info.md5Hash)) {
_logger.warning('Saved file md5 missmatch.');
throw InvalidInputException(
'Failed to save uploaded file: md5 missmatch.');
}
final sha256Hash = (await file.openRead().transform(sha256).single).bytes;
final archive = await summarizePackageArchive(
filename,
Expand Down