-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix snapshot tar symlinks validation (#4033)
* add validation for snapshot archives for not containing any symlinks * fix for test * fmt * Only allow regular file and directory entry types in snapshot archives --------- Co-authored-by: timvisee <tim@visee.me>
- Loading branch information
Showing
9 changed files
with
93 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::fs::File; | ||
use std::path::Path; | ||
|
||
use segment::common::validate_snapshot_archive::open_snapshot_archive_with_validation; | ||
use tar::Archive; | ||
|
||
use crate::operations::types::CollectionResult; | ||
|
||
pub fn validate_open_snapshot_archive<P: AsRef<Path>>( | ||
archive_path: P, | ||
) -> CollectionResult<Archive<File>> { | ||
Ok(open_snapshot_archive_with_validation(archive_path)?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::fs::File; | ||
use std::path::Path; | ||
|
||
use tar::Archive; | ||
|
||
use crate::common::operation_error::{OperationError, OperationResult}; | ||
|
||
pub fn open_snapshot_archive_with_validation<P: AsRef<Path>>( | ||
snapshot_path: P, | ||
) -> OperationResult<Archive<File>> { | ||
let path = snapshot_path.as_ref(); | ||
{ | ||
let archive_file = File::open(path).map_err(|err| { | ||
OperationError::service_error(format!( | ||
"failed to open segment snapshot archive {path:?}: {err}" | ||
)) | ||
})?; | ||
let mut ar = Archive::new(archive_file); | ||
|
||
for entry in ar.entries_with_seek()? { | ||
let entry_type = entry?.header().entry_type(); | ||
if !matches!( | ||
entry_type, | ||
tar::EntryType::Regular | tar::EntryType::Directory, | ||
) { | ||
return Err(OperationError::ValidationError { | ||
description: format!( | ||
"Malformed snapshot, tar archive contains {entry_type:?} entry", | ||
), | ||
}); | ||
} | ||
} | ||
} | ||
|
||
let archive_file = File::open(path).map_err(|err| { | ||
OperationError::service_error(format!( | ||
"failed to open segment snapshot archive {path:?}: {err}" | ||
)) | ||
})?; | ||
|
||
let mut ar = Archive::new(archive_file); | ||
ar.set_overwrite(false); | ||
|
||
Ok(ar) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters