Compare commits

...

3 Commits

Author SHA1 Message Date
Anna 33caf0802c
chore: bump version to 6.0.1 2023-08-23 00:52:20 -04:00
Anna 17a1afac16
chore: update dependencies 2023-08-23 00:52:00 -04:00
Anna f2a2373d58
fix: limit reading to the size specified 2023-08-23 00:50:59 -04:00
2 changed files with 19 additions and 9 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "ttmp"
version = "6.0.0"
version = "6.0.1"
edition = "2021"
autoexamples = true
@ -41,7 +41,7 @@ zip = { version = "0.6", default-features = false, features = ["deflate-zlib"],
[dev-dependencies]
anyhow = "1"
blake3 = { version = "1", features = ["traits-preview"] }
criterion = "0.4"
criterion = "0.5"
data-encoding = "2"
sha3 = "0.10"
tempfile = "3"

View File

@ -71,16 +71,18 @@ impl<R: Read + Seek> TtmpExtractor<R> {
let expected = file.mod_size;
let info: SqPackFileInfoHeader = read_struct(&mut data_file, &mut buf)?;
let limit = expected - std::mem::size_of::<SqPackFileInfoHeader>();
let limited = (&mut data_file).take(limit as u64);
match info.kind {
FileKind::Empty => todo!(),
FileKind::Standard => {
Self::extract_standard_file(&info, &mut data_file, &mut writer, &mut buf)?;
Self::extract_standard_file(&info, limited, &mut writer, &mut buf)?;
}
FileKind::Model => {
Self::extract_model_file(&info, &mut data_file, &mut writer, &mut buf)?;
Self::extract_model_file(&info, limited, &mut writer, &mut buf)?;
}
FileKind::Texture => {
Self::extract_texture_file(&info, &mut data_file, &mut writer, &mut buf)?;
Self::extract_texture_file(&info, limited, &mut writer, &mut buf)?;
}
}
@ -143,19 +145,22 @@ impl<R: Read> TtmpExtractor<R> {
let expected = file.mod_size;
let info: SqPackFileInfoHeader = read_struct(&mut reader, &mut buf)?;
let limit = expected - std::mem::size_of::<SqPackFileInfoHeader>();
let limited = (&mut reader).take(limit as u64);
match info.kind {
FileKind::Empty => todo!(),
FileKind::Standard => {
Self::extract_standard_file(&info, &mut reader, &mut writer, &mut buf)?;
Self::extract_standard_file(&info, limited, &mut writer, &mut buf)?;
}
FileKind::Model => {
Self::extract_model_file(&info, &mut reader, &mut writer, &mut buf)?;
Self::extract_model_file(&info, limited, &mut writer, &mut buf)?;
}
FileKind::Texture => {
Self::extract_texture_file(&info, &mut reader, &mut writer, &mut buf)?;
Self::extract_texture_file(&info, limited, &mut writer, &mut buf)?;
}
}
debug_assert!(reader.read <= expected);
if reader.read < expected {
let to_skip = expected - reader.read;
Self::skip(&mut reader, &mut buf, to_skip)?;
@ -433,7 +438,12 @@ impl<R: Read> TtmpExtractor<R> {
let mut left = amt;
while left > 0 {
let to_read = std::cmp::min(left, buf.len());
left -= reader.read(&mut buf[..to_read]).map_err(Error::Io)?;
let amt_read = reader.read(&mut buf[..to_read]).map_err(Error::Io)?;
if amt_read == 0 {
break;
}
left -= amt_read;
}
Ok(())