]> git.proxmox.com Git - pxar.git/commitdiff
decoder: more hardlink reading fixups
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 5 Jun 2020 12:00:06 +0000 (14:00 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 5 Jun 2020 12:00:08 +0000 (14:00 +0200)
the previous code use a read helper which would not allow
for there to be more data after the offset

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/decoder/mod.rs

index 78a129b7b7d380edec1133f196f205071e5d931c..3988046ebad605c164766b8bda32517207b53df8 100644 (file)
@@ -562,11 +562,17 @@ impl<I: SeqRead> DecoderImpl<I> {
     }
 
     async fn read_hardlink(&mut self) -> io::Result<format::Hardlink> {
-        let offset: u64 = self.read_simple_entry("hardlink offset").await?;
-        let size =
-            usize::try_from(self.current_header.content_size()).map_err(io_err_other)?
-            - size_of::<u64>();
-        let data = seq_read_exact_data(&mut self.input, size).await?;
+        let content_size =
+            usize::try_from(self.current_header.content_size()).map_err(io_err_other)?;
+
+        if content_size <= size_of::<u64>() {
+            io_bail!("bad hardlink entry (too small)");
+        }
+        let data_size = content_size - size_of::<u64>();
+
+        let offset: u64 = seq_read_entry(&mut self.input).await?;
+        let data = seq_read_exact_data(&mut self.input, data_size).await?;
+
         Ok(format::Hardlink { offset, data })
     }