From: Robert Obkircher <r.obkircher@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH v2 proxmox 5/6] io: remove unused append_to_vec functions
Date: Wed, 12 Aug 2026 10:23:34 +0200 [thread overview]
Message-ID: <20260812082549.21561-6-r.obkircher@proxmox.com> (raw)
In-Reply-To: <20260812082549.21561-1-r.obkircher@proxmox.com>
These functions leaked uninitialized bytes on the error paths, which
could cause undefined behavior or return sensitive data from memory.
Remove them for now, as they appear to be unused.
Signed-off-by: Robert Obkircher <r.obkircher@proxmox.com>
---
proxmox-io/src/read.rs | 32 +-------------------------------
proxmox-io/src/vec/byte_vec.rs | 14 --------------
2 files changed, 1 insertion(+), 45 deletions(-)
diff --git a/proxmox-io/src/read.rs b/proxmox-io/src/read.rs
index 0a73eea8..2cced5e0 100644
--- a/proxmox-io/src/read.rs
+++ b/proxmox-io/src/read.rs
@@ -5,7 +5,7 @@ use std::mem;
use endian_trait::Endian;
-use crate::vec::{self, ByteVecExt};
+use crate::vec;
/// Adds some additional related functionality for types implementing [`Read`](std::io::Read).
///
@@ -22,9 +22,6 @@ use crate::vec::{self, ByteVecExt};
/// // read some bytes into a newly allocated Vec<u8>:
/// let mut data = file.read_exact_allocated(64)?;
///
-/// // appending data to a vector:
-/// let actually_appended = file.append_to_vec(&mut data, 64)?; // .read() version
-/// file.append_exact_to_vec(&mut data, 64)?; // .read_exact() version
/// # Ok(())
/// # }
/// ```
@@ -71,12 +68,6 @@ pub trait ReadExt {
/// ```
fn read_exact_allocated(&mut self, size: usize) -> io::Result<Vec<u8>>;
- /// Append data to a vector, growing it as necessary. Returns the amount of data appended.
- fn append_to_vec(&mut self, out: &mut Vec<u8>, size: usize) -> io::Result<usize>;
-
- /// Append an exact amount of data to a vector, growing it as necessary.
- fn append_exact_to_vec(&mut self, out: &mut Vec<u8>, size: usize) -> io::Result<()>;
-
/// Read a value with host endianness.
///
/// This is limited to types implementing the [`Endian`] trait under the assumption that
@@ -244,27 +235,6 @@ impl<R: io::Read> ReadExt for R {
Ok(out)
}
- fn append_to_vec(&mut self, out: &mut Vec<u8>, size: usize) -> io::Result<usize> {
- let pos = out.len();
- unsafe {
- out.grow_uninitialized(size);
- }
- let got = self.read(&mut out[pos..])?;
- unsafe {
- out.set_len(pos + got);
- }
- Ok(got)
- }
-
- fn append_exact_to_vec(&mut self, out: &mut Vec<u8>, size: usize) -> io::Result<()> {
- let pos = out.len();
- unsafe {
- out.grow_uninitialized(size);
- }
- self.read_exact(&mut out[pos..])?;
- Ok(())
- }
-
unsafe fn read_host_value<T: Endian>(&mut self) -> io::Result<T> {
let mut value = std::mem::MaybeUninit::<T>::uninit();
unsafe {
diff --git a/proxmox-io/src/vec/byte_vec.rs b/proxmox-io/src/vec/byte_vec.rs
index e8d1962b..0a45ba0a 100644
--- a/proxmox-io/src/vec/byte_vec.rs
+++ b/proxmox-io/src/vec/byte_vec.rs
@@ -25,13 +25,6 @@
/// # }
/// ```
///
-/// Note that this module also provides a safe alternative for the case where
-/// `grow_uninitialized()` is directly followed by a `read_exact()` call via the [`ReadExt`]
-/// trait:
-/// ```ignore
-/// file.append_to_vec(&mut data, 1024)?;
-/// ```
-///
/// [`ReadExt`]: crate::ReadExt
pub trait ByteVecExt {
/// Grow a vector without initializing its elements. The difference to simply using `reserve`
@@ -57,13 +50,6 @@ pub trait ByteVecExt {
/// # }
/// ```
///
- /// Although for the above case it is recommended to use the even shorter version from the
- /// [`ReadExt`] trait:
- /// ```ignore
- /// // use crate::tools::vec::ByteVecExt;
- /// file.append_to_vec(&mut buffer, 1024)?;
- /// ```
- ///
/// # Safety
///
/// When increasing the size, the new contents are uninitialized and have nothing to do with
--
2.47.3
next prev parent reply other threads:[~2026-08-12 8:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 8:23 [PATCH v2 proxmox 0/6] uninitialized memory allocations fixes Robert Obkircher
2026-08-12 8:23 ` [PATCH v2 proxmox 1/6] uuid: avoid potential null dereference and memory leaks Robert Obkircher
2026-08-12 8:23 ` [PATCH v2 proxmox 2/6] io: request zeroed memory instead of manually clearing it Robert Obkircher
2026-08-12 8:23 ` [PATCH v2 proxmox 3/6] io: avoid potential null dereference and memory leak on error path Robert Obkircher
2026-08-12 8:23 ` [PATCH v2 proxmox 4/6] io: remove boxed::uninitialized because it is unsound Robert Obkircher
2026-08-12 8:23 ` Robert Obkircher [this message]
2026-08-12 8:23 ` [PATCH v2 proxmox 6/6] io: remove unused ByteVecExt trait with grow_ and resize_uninitialized Robert Obkircher
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=20260812082549.21561-6-r.obkircher@proxmox.com \
--to=r.obkircher@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.