From: Christian Ebner <c.ebner@proxmox.com>
To: Robert Obkircher <r.obkircher@proxmox.com>, pbs-devel@lists.proxmox.com
Subject: Re: [PATCH proxmox-backup 6/9] datastore: check that index files are regular files
Date: Mon, 14 Sep 2026 13:17:02 +0200 [thread overview]
Message-ID: <b46acb3f-384c-466a-a31d-8add846dc279@proxmox.com> (raw)
In-Reply-To: <20260731142430.289893-7-r.obkircher@proxmox.com>
Two nits inline.
On 7/31/26 4:25 PM, Robert Obkircher wrote:
> Return an explicit error message when trying to mmap something other
> than a regular file. Previously, this was caught implicitly by the
> non-zero size check or by a failing seek.
>
> Signed-off-by: Robert Obkircher <r.obkircher@proxmox.com>
> ---
> pbs-datastore/src/dynamic_index.rs | 16 ++++++++--------
> pbs-datastore/src/fixed_index.rs | 15 ++++++++-------
> 2 files changed, 16 insertions(+), 15 deletions(-)
>
> diff --git a/pbs-datastore/src/dynamic_index.rs b/pbs-datastore/src/dynamic_index.rs
> index 7ee8bdcab..dd0b86f3f 100644
> --- a/pbs-datastore/src/dynamic_index.rs
> +++ b/pbs-datastore/src/dynamic_index.rs
> @@ -8,6 +8,7 @@ use std::sync::{Arc, Mutex};
> use std::task::Context;
>
> use anyhow::{Error, bail, format_err};
> +use nix::sys::stat::{SFlag, fstat};
>
> use proxmox_io::ReadExt;
> use proxmox_sys::mmap::Mmap;
> @@ -96,17 +97,16 @@ impl DynamicIndexReader {
> }
>
> pub fn new(mut file: std::fs::File) -> Result<Self, Error> {
> + let stat = fstat(file.as_raw_fd()).map_err(|e| format_err!("fstat failed - {e}"))?;
> + if (stat.st_mode & SFlag::S_IFMT.bits()) != SFlag::S_IFREG.bits() {
> + bail!("not a regular file");
> + }
> +
> // FIXME: This is NOT OUR job! Check the callers of this method and remove this!
> file.seek(SeekFrom::Start(0))?;
>
> let header_size = std::mem::size_of::<DynamicIndexHeader>();
>
> - let rawfd = file.as_raw_fd();
> - let stat = match nix::sys::stat::fstat(rawfd) {
> - Ok(stat) => stat,
> - Err(err) => bail!("fstat failed - {}", err),
> - };
> -
> let size = stat.st_size as usize;
>
> if size < header_size {
> @@ -611,11 +611,11 @@ mod tests {
>
> check_error_contains(
> DynamicIndexReader::open(Path::new("/dev/stdin")),
> - "Illegal seek",
> + "not a regular file",
> );
> check_error_contains(
> DynamicIndexReader::open(Path::new("/dev/zero")),
> - "index too small (0)",
> + "not a regular file",
> );
nit: this check is now somewhat redundant? The check for to small index
is already performed further below, so this can be dropped IMO.
>
> let path = dir.path().join("file");
> diff --git a/pbs-datastore/src/fixed_index.rs b/pbs-datastore/src/fixed_index.rs
> index 0145f93d3..1d3d0170a 100644
> --- a/pbs-datastore/src/fixed_index.rs
> +++ b/pbs-datastore/src/fixed_index.rs
> @@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
> use std::ptr::NonNull;
>
> use anyhow::{Context, Error, bail, format_err};
> +use nix::sys::stat::{SFlag, fstat};
>
> use proxmox_io::ReadExt;
> use proxmox_uuid::Uuid;
> @@ -60,15 +61,15 @@ impl FixedIndexReader {
> }
>
> pub fn new(mut file: std::fs::File) -> Result<Self, Error> {
> + let stat = fstat(file.as_raw_fd()).map_err(|e| format_err!("fstat failed - {e}"))?;
> + if (stat.st_mode & SFlag::S_IFMT.bits()) != SFlag::S_IFREG.bits() {
> + bail!("not a regular file");
> + }
> +
> file.seek(SeekFrom::Start(0))?;
>
> let header_size = std::mem::size_of::<FixedIndexHeader>();
>
> - let stat = match nix::sys::stat::fstat(file.as_raw_fd()) {
> - Ok(stat) => stat,
> - Err(err) => bail!("fstat failed - {}", err),
> - };
> -
> let size = stat.st_size as usize;
>
> if size < header_size {
> @@ -608,11 +609,11 @@ mod tests {
>
> check_error_contains(
> FixedIndexReader::open(Path::new("/dev/stdin")),
> - "Illegal seek",
> + "not a regular file",
> );
> check_error_contains(
> FixedIndexReader::open(Path::new("/dev/zero")),
> - "index too small (0)",
> + "not a regular file",
> );
nit: same as above, the second error testcase is now redundant.
>
> let path = dir.path().join("file");
next prev parent reply other threads:[~2026-09-14 11:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 14:21 [PATCH proxmox{,-backup} 0/9] support index readers on larger page sizes Robert Obkircher
2026-07-31 14:21 ` [PATCH proxmox 1/9] proxmox-sys: add len and as_non_null method to Mmap Robert Obkircher
2026-07-31 14:21 ` [PATCH proxmox-backup 2/9] datastore: limit scope of mutable reference in FixedIndexWriter::close Robert Obkircher
2026-07-31 14:21 ` [PATCH proxmox-backup 3/9] datastore: add tests for fixed and dynamic index reader Robert Obkircher
2026-07-31 14:21 ` [PATCH proxmox-backup 4/9] datastore: fix inconsistent implementation of index_size method Robert Obkircher
2026-07-31 14:21 ` [PATCH proxmox-backup 5/9] bin: debug: print referenced backup size for index files Robert Obkircher
2026-07-31 14:21 ` [PATCH proxmox-backup 6/9] datastore: check that index files are regular files Robert Obkircher
2026-09-14 11:17 ` Christian Ebner [this message]
2026-07-31 14:21 ` [PATCH proxmox-backup 7/9] datastore: simplify FixedIndexReader::chunk_info Robert Obkircher
2026-07-31 14:21 ` [PATCH proxmox-backup 8/9] datastore: always access dynamic index reader slice through method Robert Obkircher
2026-07-31 14:21 ` [PATCH proxmox-backup 9/9] fix #7244: datastore: always mmap index files from offset 0 Robert Obkircher
2026-09-14 11:47 ` [PATCH proxmox{,-backup} 0/9] support index readers on larger page sizes Christian Ebner
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=b46acb3f-384c-466a-a31d-8add846dc279@proxmox.com \
--to=c.ebner@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
--cc=r.obkircher@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox