Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Check file size of snapshot_version when unarchiving snapshot #21925

Merged
merged 10 commits into from
Dec 17, 2021

Conversation

mooori
Copy link
Contributor

@mooori mooori commented Dec 15, 2021

Problem

The size of the snapshot_version file is not checked, which is an attack vector. See #18504, #18841.

Summary of Changes

Check the size of the file containing the snapshot_version before opening it. If the size exceeds MAX_SNAPSHOT_VERSION_FILE_SIZE, an error is returned and the file will not be opened.

Notes

  • MAX_SNAPSHOT_VERSION_FILE_SIZE was chosen arbitrarily - let me know if another value makes more sense.
  • If the file size is too big, an error is created and returned according to other code in snapshot_utils dealing with files that are too big (namely create_snapshot_data_file_stream).

Test

So far, there is no dedicated test for unarchive_snapshot. Setting up such a test just to verify the snapshot_version file size is checked correctly looks like overkill.

Fixes #18841

@mergify mergify bot added the community Community contribution label Dec 15, 2021
@mergify mergify bot requested a review from a team December 15, 2021 16:11
@mvines mvines requested a review from brooksprumo December 15, 2021 16:39
@mvines
Copy link
Contributor

mvines commented Dec 15, 2021

Oh nice. This PR lgtm but @brooksprumo can you please take a look as well for a full review

@brooksprumo
Copy link
Contributor

@mooori Thank you for your submission! Please mark the PR as "Ready for review" when you feel it's completed and I will take a look.

@mooori
Copy link
Contributor Author

mooori commented Dec 15, 2021

@brooksprumo CI checks haven't finished yet, but since it's just a small PR I think it's good to go (status is updated).

If there should be any issues, I'll be back later. I ran cargo test, cargo fmt and cargo clippy locally inside runtime and they didn't complain.

@mooori mooori marked this pull request as ready for review December 15, 2021 17:14
@codecov
Copy link

codecov bot commented Dec 15, 2021

Codecov Report

Merging #21925 (96c39dc) into master (56ec524) will decrease coverage by 0.0%.
The diff coverage is 100.0%.

@@            Coverage Diff            @@
##           master   #21925     +/-   ##
=========================================
- Coverage    81.3%    81.2%   -0.1%     
=========================================
  Files         516      516             
  Lines      144323   144346     +23     
=========================================
- Hits       117347   117346      -1     
- Misses      26976    27000     +24     

Copy link
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! I'm requesting some small tweaks.

Also:

So far, there is no dedicated test for unarchive_snapshot. Setting up such a test just to verify the snapshot_version file size is checked correctly looks like overkill.

I'd like tests for the file-to-snapshot-version function (see comments below). Those tests do not necessarily need to be part of this PR though. If you'd rather not add the tests here, please create a new issue name something like "Add tests for snapshot_version_from_file" and mark it as "good first issue".

I'd like two tests:

  1. Ensure that a version file with the default SnapshotVersion passes
  2. Ensure that a version file with a size MAX_SNAPSHOT_VERSION_FILE_SIZE + 1 fails

@brooksprumo
Copy link
Contributor

Oh, also please re-request a review from me once the changes are made. This way I'll make sure to see the review request in my GH dashboard.

@jstarry jstarry removed the request for review from a team December 16, 2021 14:46
@mergify mergify bot dismissed brooksprumo’s stale review December 16, 2021 18:00

Pull request has been modified.

@mergify mergify bot requested a review from a team December 16, 2021 18:01
@mooori
Copy link
Contributor Author

mooori commented Dec 16, 2021

Thank you for the review @brooksprumo. The suggestions have been implemented (including tests).

@mooori mooori requested review from brooksprumo and removed request for a team December 16, 2021 18:03
@mergify mergify bot requested a review from a team December 16, 2021 18:04
Copy link
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Two more small things and then I think it'll be all set!

@brooksprumo brooksprumo removed the request for review from a team December 16, 2021 18:42
@mooori mooori requested a review from brooksprumo December 17, 2021 10:43
@mergify mergify bot dismissed brooksprumo’s stale review December 17, 2021 10:44

Pull request has been modified.

@mergify mergify bot requested a review from a team December 17, 2021 10:44
@brooksprumo brooksprumo removed the request for review from a team December 17, 2021 15:48
Copy link
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks again for your submission, @mooori!

@brooksprumo brooksprumo merged commit 0f6e8d3 into solana-labs:master Dec 17, 2021
mergify bot pushed a commit that referenced this pull request Dec 17, 2021
(cherry picked from commit 0f6e8d3)

# Conflicts:
#	runtime/src/snapshot_utils.rs
mergify bot pushed a commit that referenced this pull request Dec 17, 2021
@brooksprumo brooksprumo added v1.8 and removed v1.8 labels Dec 17, 2021
@brooksprumo
Copy link
Contributor

@Mergifyio backport v1.8

@mergify
Copy link
Contributor

mergify bot commented Dec 17, 2021

backport v1.8

✅ Backports have been created

mergify bot added a commit that referenced this pull request Dec 17, 2021
@mooori mooori deleted the snapshot-version-filesize branch December 20, 2021 07:54
@mooori mooori restored the snapshot-version-filesize branch December 20, 2021 07:55
@mooori mooori deleted the snapshot-version-filesize branch December 20, 2021 07:56
@brooksprumo brooksprumo mentioned this pull request Jan 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community Community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check file size of snapshot_version when unarchiving snapshot
3 participants