From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id C169D1FF170
	for <inbox@lore.proxmox.com>; Tue, 17 Dec 2024 16:16:56 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id D1985466A;
	Tue, 17 Dec 2024 16:17:07 +0100 (CET)
From: Filip Schauer <f.schauer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Tue, 17 Dec 2024 16:17:01 +0100
Message-Id: <20241217151701.156187-1-f.schauer@proxmox.com>
X-Mailer: git-send-email 2.39.5
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.025 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pbs-devel] [PATCH vma-to-pbs] improve error message for unexpected
 end of VMA file
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>

When a VMA file ends unexpectedly while reading the header, change the
error message from "failed to fill whole buffer" to "Unexpected end of
VMA file" for more clarity.

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
 src/vma.rs | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/vma.rs b/src/vma.rs
index 63ee3b5..978e4c7 100644
--- a/src/vma.rs
+++ b/src/vma.rs
@@ -1,4 +1,5 @@
 use std::collections::HashSet;
+use std::io;
 use std::io::Read;
 use std::mem::size_of;
 use std::str;
@@ -126,7 +127,13 @@ impl<T: Read> VmaReader<T> {
 
     fn read_header(vma_file: &mut T) -> Result<VmaHeader, Error> {
         let mut buffer = vec![0; VMA_HEADER_SIZE_NO_BLOB_BUFFER];
-        vma_file.read_exact(&mut buffer)?;
+        vma_file.read_exact(&mut buffer).map_err(|e| {
+            if e.kind() == io::ErrorKind::UnexpectedEof {
+                io::Error::new(io::ErrorKind::UnexpectedEof, "Unexpected end of VMA file")
+            } else {
+                e
+            }
+        })?;
 
         let bincode_options = bincode::DefaultOptions::new()
             .with_fixint_encoding()
@@ -298,9 +305,9 @@ impl<T: Read> VmaReader<T> {
         loop {
             match self.restore_extent(&callback) {
                 Ok(()) => {}
-                Err(e) => match e.downcast_ref::<std::io::Error>() {
+                Err(e) => match e.downcast_ref::<io::Error>() {
                     Some(ioerr) => {
-                        if ioerr.kind() == std::io::ErrorKind::UnexpectedEof {
+                        if ioerr.kind() == io::ErrorKind::UnexpectedEof {
                             break; // Break out of the loop since the end of the file was reached.
                         } else {
                             return Err(format_err!(e)).context("Failed to read VMA file");
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel