diff options
Diffstat (limited to 'vendor/gix-odb/src')
-rw-r--r-- | vendor/gix-odb/src/find.rs | 6 | ||||
-rw-r--r-- | vendor/gix-odb/src/lib.rs | 2 | ||||
-rw-r--r-- | vendor/gix-odb/src/sink.rs | 10 | ||||
-rw-r--r-- | vendor/gix-odb/src/store_impls/dynamic/load_index.rs | 2 | ||||
-rw-r--r-- | vendor/gix-odb/src/store_impls/loose/find.rs | 31 | ||||
-rw-r--r-- | vendor/gix-odb/src/store_impls/loose/write.rs | 19 |
6 files changed, 34 insertions, 36 deletions
diff --git a/vendor/gix-odb/src/find.rs b/vendor/gix-odb/src/find.rs index bf807e27c..196845c4d 100644 --- a/vendor/gix-odb/src/find.rs +++ b/vendor/gix-odb/src/find.rs @@ -104,11 +104,11 @@ mod header { } } - impl From<(usize, gix_object::Kind)> for Header { - fn from((object_size, kind): (usize, gix_object::Kind)) -> Self { + impl From<(u64, gix_object::Kind)> for Header { + fn from((object_size, kind): (u64, gix_object::Kind)) -> Self { Header::Loose { kind, - size: object_size as u64, + size: object_size, } } } diff --git a/vendor/gix-odb/src/lib.rs b/vendor/gix-odb/src/lib.rs index 5aee76ca2..a6aa4caee 100644 --- a/vendor/gix-odb/src/lib.rs +++ b/vendor/gix-odb/src/lib.rs @@ -50,7 +50,7 @@ pub struct Cache<S> { pub mod cache; /// -/// It can optionally compress the content, similarly to what would happen when using a [`loose::Store`][crate::loose::Store]. +/// It can optionally compress the content, similarly to what would happen when using a [`loose::Store`]. /// #[derive(Clone)] pub struct Sink { diff --git a/vendor/gix-odb/src/sink.rs b/vendor/gix-odb/src/sink.rs index f6334a51c..7784901a8 100644 --- a/vendor/gix-odb/src/sink.rs +++ b/vendor/gix-odb/src/sink.rs @@ -1,6 +1,5 @@ use std::{ cell::RefCell, - convert::TryInto, io::{self, Write}, }; @@ -24,11 +23,10 @@ impl crate::traits::Write for Sink { fn write_stream( &self, kind: gix_object::Kind, - size: u64, + mut size: u64, from: &mut dyn io::Read, ) -> Result<gix_hash::ObjectId, crate::write::Error> { - let mut size = size.try_into().expect("object size to fit into usize"); - let mut buf = [0u8; 8096]; + let mut buf = [0u8; u16::MAX as usize]; let header = gix_object::encode::loose_header(kind, size); let possibly_compress = |buf: &[u8]| -> io::Result<()> { @@ -43,11 +41,11 @@ impl crate::traits::Write for Sink { possibly_compress(&header).map_err(Box::new)?; while size != 0 { - let bytes = size.min(buf.len()); + let bytes = (size as usize).min(buf.len()); from.read_exact(&mut buf[..bytes]).map_err(Box::new)?; hasher.update(&buf[..bytes]); possibly_compress(&buf[..bytes]).map_err(Box::new)?; - size -= bytes; + size -= bytes as u64; } if let Some(compressor) = self.compressor.as_ref() { let mut c = compressor.borrow_mut(); diff --git a/vendor/gix-odb/src/store_impls/dynamic/load_index.rs b/vendor/gix-odb/src/store_impls/dynamic/load_index.rs index 4716a5806..a255f6c4b 100644 --- a/vendor/gix-odb/src/store_impls/dynamic/load_index.rs +++ b/vendor/gix-odb/src/store_impls/dynamic/load_index.rs @@ -711,7 +711,7 @@ impl PartialEq<Self> for Either { impl PartialOrd<Self> for Either { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { - self.path().partial_cmp(other.path()) + Some(self.path().cmp(other.path())) } } diff --git a/vendor/gix-odb/src/store_impls/loose/find.rs b/vendor/gix-odb/src/store_impls/loose/find.rs index 91bf0ba87..4116a0453 100644 --- a/vendor/gix-odb/src/store_impls/loose/find.rs +++ b/vendor/gix-odb/src/store_impls/loose/find.rs @@ -14,13 +14,11 @@ pub enum Error { path: PathBuf, }, #[error("file at '{path}' showed invalid size of inflated data, expected {expected}, got {actual}")] - SizeMismatch { - actual: usize, - expected: usize, - path: PathBuf, - }, + SizeMismatch { actual: u64, expected: u64, path: PathBuf }, #[error(transparent)] Decode(#[from] gix_object::decode::LooseHeaderDecodeError), + #[error("Cannot store {size} in memory as it's not representable")] + OutOfMemory { size: u64 }, #[error("Could not {action} data at '{path}'")] Io { source: std::io::Error, @@ -137,7 +135,7 @@ impl Store { /// Return only the decompressed size of the object and its kind without fully reading it into memory as tuple of `(size, kind)`. /// Returns `None` if `id` does not exist in the database. - pub fn try_header(&self, id: &gix_hash::oid) -> Result<Option<(usize, gix_object::Kind)>, Error> { + pub fn try_header(&self, id: &gix_hash::oid) -> Result<Option<(u64, gix_object::Kind)>, Error> { const BUF_SIZE: usize = 256; let mut buf = [0_u8; BUF_SIZE]; let path = hash_path(id, self.path.clone()); @@ -224,16 +222,17 @@ impl Store { let decompressed_body_bytes_sans_header = decompressed_start + header_size..decompressed_start + consumed_out; - if consumed_out != size + header_size { + if consumed_out as u64 != size + header_size as u64 { return Err(Error::SizeMismatch { - expected: size + header_size, - actual: consumed_out, + expected: size + header_size as u64, + actual: consumed_out as u64, path, }); } buf.copy_within(decompressed_body_bytes_sans_header, 0); } else { - buf.resize(bytes_read + size + header_size, 0); + let new_len = bytes_read as u64 + size + header_size as u64; + buf.resize(new_len.try_into().map_err(|_| Error::OutOfMemory { size: new_len })?, 0); { let (input, output) = buf.split_at_mut(bytes_read); let num_decompressed_bytes = zlib::stream::inflate::read( @@ -246,17 +245,21 @@ impl Store { action: "deflate", path: path.to_owned(), })?; - if num_decompressed_bytes + consumed_out != size + header_size { + if num_decompressed_bytes as u64 + consumed_out as u64 != size + header_size as u64 { return Err(Error::SizeMismatch { - expected: size + header_size, - actual: num_decompressed_bytes + consumed_out, + expected: size + header_size as u64, + actual: num_decompressed_bytes as u64 + consumed_out as u64, path, }); } }; buf.copy_within(decompressed_start + header_size.., 0); } - buf.resize(size, 0); + buf.resize( + size.try_into() + .expect("BUG: here the size is already confirmed to fit into memory"), + 0, + ); Ok(gix_object::Data { kind, data: buf }) } } diff --git a/vendor/gix-odb/src/store_impls/loose/write.rs b/vendor/gix-odb/src/store_impls/loose/write.rs index e537eda92..2cac12d18 100644 --- a/vendor/gix-odb/src/store_impls/loose/write.rs +++ b/vendor/gix-odb/src/store_impls/loose/write.rs @@ -1,4 +1,4 @@ -use std::{convert::TryInto, fs, io, io::Write, path::PathBuf}; +use std::{fs, io, io::Write, path::PathBuf}; use gix_features::{hash, zlib::stream::deflate}; use gix_object::WriteTo; @@ -48,7 +48,7 @@ impl crate::traits::Write for Store { /// This will cost at least 4 IO operations. fn write_buf(&self, kind: gix_object::Kind, from: &[u8]) -> Result<gix_hash::ObjectId, crate::write::Error> { let mut to = self.dest().map_err(Box::new)?; - to.write_all(&gix_object::encode::loose_header(kind, from.len())) + to.write_all(&gix_object::encode::loose_header(kind, from.len() as u64)) .map_err(|err| Error::Io { source: err, message: "write header to tempfile in", @@ -74,15 +74,12 @@ impl crate::traits::Write for Store { mut from: &mut dyn io::Read, ) -> Result<gix_hash::ObjectId, crate::write::Error> { let mut to = self.dest().map_err(Box::new)?; - to.write_all(&gix_object::encode::loose_header( - kind, - size.try_into().expect("object size to fit into usize"), - )) - .map_err(|err| Error::Io { - source: err, - message: "write header to tempfile in", - path: self.path.to_owned(), - })?; + to.write_all(&gix_object::encode::loose_header(kind, size)) + .map_err(|err| Error::Io { + source: err, + message: "write header to tempfile in", + path: self.path.to_owned(), + })?; io::copy(&mut from, &mut to) .map_err(|err| Error::Io { |