From: Robert Obkircher <r.obkircher@proxmox.com>
To: "Max R. Carrara" <m.carrara@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [PATCH proxmox-backup v2 06/10] tape: tape block: represent tape block header with its own struct
Date: Mon, 7 Sep 2026 15:03:42 +0200 [thread overview]
Message-ID: <a74c3420-75ef-4fa2-abec-5c2d3ea1a166@proxmox.com> (raw)
In-Reply-To: <DL923U1SA8WH.3IWHF8ID78OKX@proxmox.com>
On 07.09.26 13:44, Max R. Carrara wrote:
> On Wed Sep 2, 2026 at 6:17 PM CEST, Robert Obkircher wrote:
>>> [..]
>>>
>>> + /// Returns the entirety of the tape block, meaning both its header and data
>>> + /// payload, as a byte slice.
>>> + pub fn as_bytes(&self) -> &[u8] {
>>> + // SAFETY:
>>> + // - Since `self` is a reference, we can convert it to a pointer without
>>> + // any concerns. The resulting pointer is always valid and non-null.
>> This point doesn't seem worth mentioning, especially if you leave out
>> the more important ones like the fact that the struct doesn't contain
>> any (uninitialized) padding bytes or interior mutability.
> Good point, will add in v2. Thanks!
>
>>> + // - The pointer used here is not used or aliased anywhere else.
>> This is neither true nor relevant. e.g. if you call as_bytes twice it
>> will be aliased.
> Right, but I was referring to the pointer that is `self as *const _` (or
> `self as *mut _`) -- that pointer specifically is not aliased anywhere
> else, meaning that the returned references are always valid and respect
> Rust's ownership model.
>
> All that being said, I should probably rephrase this to be more precise.
> Thanks a lot, will fix in v2!
I still don't understand what you mean by "not aliased".
For &mut self you can argue that you have exclusive access, but for
&self you have to assume that other references exist.
>>> + // - We allocated `*self` with a total size of `Self::SIZE` earlier,
>>> + // meaning that the resulting slice never goes out of bounds.
>> Relying on the fact that no other constructor exists seems like a bad
>> idea. Just use `size_of_val(self)`.
> Good point actually, since we just return a byte slice. Didn't think of
> that. Will fix in v2, thanks!
>
>>> + // - The resulting slice never outlives `self`.
>>> + unsafe { std::slice::from_raw_parts((self as *const _) as *const u8, Self::SIZE) }
>> I'd prefer `ptr::from_ref(self).cast()` to avoid the _
> ACK, will fix in v2. Thanks!
>
next prev parent reply other threads:[~2026-09-07 13:03 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 14:02 [PATCH proxmox{,-backup} v2 00/10] Fix Undefined Behavior in Tape Block Header Deallocation Max R. Carrara
2026-08-21 14:02 ` [PATCH proxmox v2 01/10] proxmox-alloc: introduce proxmox-alloc with `LayoutAwareBox<T>` type Max R. Carrara
2026-09-02 16:14 ` Robert Obkircher
2026-09-07 11:44 ` Max R. Carrara
2026-09-07 12:50 ` Robert Obkircher
2026-09-07 13:40 ` Max R. Carrara
2026-08-21 14:02 ` [PATCH proxmox v2 02/10] proxmox-alloc: document undefined behavior regarding custom allocs Max R. Carrara
2026-09-02 16:14 ` Robert Obkircher
2026-09-07 11:44 ` Max R. Carrara
2026-09-02 16:17 ` Robert Obkircher
2026-09-07 11:44 ` Max R. Carrara
2026-08-21 14:02 ` [PATCH proxmox-backup v2 03/10] tape: move tape block structs into separate file module Max R. Carrara
2026-09-02 16:17 ` Robert Obkircher
2026-09-07 11:44 ` Max R. Carrara
2026-08-21 14:02 ` [PATCH proxmox-backup v2 04/10] tape: rename `BlockHeader` and `BlockHeaderFlags` Max R. Carrara
2026-08-21 14:02 ` [PATCH proxmox-backup v2 05/10] tape: blocked_{reader,writer}: rename `buffer` to `tape_block` Max R. Carrara
2026-08-21 14:02 ` [PATCH proxmox-backup v2 06/10] tape: tape block: represent tape block header with its own struct Max R. Carrara
2026-09-02 16:17 ` Robert Obkircher
2026-09-07 11:44 ` Max R. Carrara
2026-09-07 13:03 ` Robert Obkircher [this message]
2026-08-21 14:02 ` [PATCH proxmox-backup v2 07/10] tape: tape block: make `payload` field private Max R. Carrara
2026-08-21 14:02 ` [PATCH proxmox-backup v2 08/10] tape: blocked_{reader,writer}: remove haphazard `unsafe` blocks Max R. Carrara
2026-08-21 14:02 ` [PATCH proxmox-backup v2 09/10] tape: tape block: fix undefined behavior on tape block deallocation Max R. Carrara
2026-08-21 14:02 ` [PATCH proxmox-backup v2 10/10] tape: sgutils2: fix undefined behavior in dealloc of buffer Max R. Carrara
2026-09-02 16:36 ` [PATCH proxmox{,-backup} v2 00/10] Fix Undefined Behavior in Tape Block Header Deallocation Robert Obkircher
2026-09-07 11:44 ` Max R. Carrara
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=a74c3420-75ef-4fa2-abec-5c2d3ea1a166@proxmox.com \
--to=r.obkircher@proxmox.com \
--cc=m.carrara@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.