summaryrefslogtreecommitdiffstats
path: root/vendor/gix-odb/src/store_impls/loose
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gix-odb/src/store_impls/loose')
-rw-r--r--vendor/gix-odb/src/store_impls/loose/find.rs31
-rw-r--r--vendor/gix-odb/src/store_impls/loose/write.rs19
2 files changed, 25 insertions, 25 deletions
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 {