From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 3/4] sync: verify size and checksum of pulled archives
Date: Mon, 3 Aug 2020 14:10:45 +0200 [thread overview]
Message-ID: <20200803121046.3623216-4-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20200803121046.3623216-1-f.gruenbichler@proxmox.com>
and not just of previously synced ones.
we can't use BackupManifest::verify_file as the archive is still stored
under the tmp path at this point.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
src/client/pull.rs | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/src/client/pull.rs b/src/client/pull.rs
index 629e8266..429ab458 100644
--- a/src/client/pull.rs
+++ b/src/client/pull.rs
@@ -62,15 +62,32 @@ async fn download_manifest(
Ok(tmp_manifest_file)
}
+fn verify_archive(
+ info: &FileInfo,
+ csum: &[u8; 32],
+ size: u64,
+) -> Result<(), Error> {
+ if size != info.size {
+ bail!("wrong size for file '{}' ({} != {})", info.filename, info.size, size);
+ }
+
+ if csum != &info.csum {
+ bail!("wrong checksum for file '{}'", info.filename);
+ }
+
+ Ok(())
+}
+
async fn pull_single_archive(
worker: &WorkerTask,
reader: &BackupReader,
chunk_reader: &mut RemoteChunkReader,
tgt_store: Arc<DataStore>,
snapshot: &BackupDir,
- archive_name: &str,
+ archive_info: &FileInfo,
) -> Result<(), Error> {
+ let archive_name = &archive_info.filename;
let mut path = tgt_store.base_path();
path.push(snapshot.relative_path());
path.push(archive_name);
@@ -91,16 +108,23 @@ async fn pull_single_archive(
ArchiveType::DynamicIndex => {
let index = DynamicIndexReader::new(tmpfile)
.map_err(|err| format_err!("unable to read dynamic index {:?} - {}", tmp_path, err))?;
+ let (csum, size) = index.compute_csum();
+ verify_archive(archive_info, &csum, size)?;
pull_index_chunks(worker, chunk_reader, tgt_store.clone(), index).await?;
}
ArchiveType::FixedIndex => {
let index = FixedIndexReader::new(tmpfile)
.map_err(|err| format_err!("unable to read fixed index '{:?}' - {}", tmp_path, err))?;
+ let (csum, size) = index.compute_csum();
+ verify_archive(archive_info, &csum, size)?;
pull_index_chunks(worker, chunk_reader, tgt_store.clone(), index).await?;
}
- ArchiveType::Blob => { /* nothing to do */ }
+ ArchiveType::Blob => {
+ let (csum, size) = compute_file_csum(&mut tmpfile)?;
+ verify_archive(archive_info, &csum, size)?;
+ }
}
if let Err(err) = std::fs::rename(&tmp_path, &path) {
bail!("Atomic rename file {:?} failed - {}", path, err);
@@ -248,7 +272,7 @@ async fn pull_snapshot(
&mut chunk_reader,
tgt_store.clone(),
snapshot,
- &item.filename,
+ &item,
).await?;
}
--
2.20.1
next prev parent reply other threads:[~2020-08-03 12:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-03 12:10 [pbs-devel] [PATCH proxmox-backup 0/4] add missing digest verification Fabian Grünbichler
2020-08-03 12:10 ` [pbs-devel] [PATCH proxmox-backup 1/4] blobs: attempt to verify on decode when possible Fabian Grünbichler
2020-08-03 12:10 ` [pbs-devel] [PATCH proxmox-backup 2/4] sync: verify chunk size and digest, if possible Fabian Grünbichler
2020-08-03 12:10 ` Fabian Grünbichler [this message]
2020-08-03 12:10 ` [pbs-devel] [PATCH proxmox-backup 4/4] datastore: allow browsing signed pxar files Fabian Grünbichler
2020-08-04 5:29 ` [pbs-devel] applied: [PATCH proxmox-backup 0/4] add missing digest verification Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200803121046.3623216-4-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.