summaryrefslogtreecommitdiffstats
path: root/vendor/miniz_oxide
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/miniz_oxide')
-rw-r--r--vendor/miniz_oxide/.cargo-checksum.json2
-rw-r--r--vendor/miniz_oxide/Cargo.toml6
-rw-r--r--vendor/miniz_oxide/Readme.md19
-rw-r--r--vendor/miniz_oxide/src/inflate/core.rs5
-rw-r--r--vendor/miniz_oxide/src/inflate/mod.rs102
-rw-r--r--vendor/miniz_oxide/src/inflate/stream.rs3
-rw-r--r--vendor/miniz_oxide/src/lib.rs10
7 files changed, 112 insertions, 35 deletions
diff --git a/vendor/miniz_oxide/.cargo-checksum.json b/vendor/miniz_oxide/.cargo-checksum.json
index 16e89c510..e237f121c 100644
--- a/vendor/miniz_oxide/.cargo-checksum.json
+++ b/vendor/miniz_oxide/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"14ec71e104b90decb8b84170557138a51cc39a8b83b721d74eb476fb13f6bdd2","LICENSE":"e190940e8ad3cdd4fca962a6508ed6865d589d314b1cb055f86000e124b88d8d","LICENSE-APACHE.md":"0d542e0c8804e39aa7f37eb00da5a762149dc682d7829451287e11b938e94594","LICENSE-MIT.md":"e190940e8ad3cdd4fca962a6508ed6865d589d314b1cb055f86000e124b88d8d","LICENSE-ZLIB.md":"c89bcc058da12a0fb24402b8ea4542a21515dd1da2e8c67bba4ed9bd269f1c96","Readme.md":"b6a6668b073a3356748b642ce51b31233b6408ffcca3e52801ef473a9f7925c7","src/deflate/buffer.rs":"76bcca4e79bef412eeebdd06d2d0a4348ed9ee17edbdaa6d451d8bf03b1cde85","src/deflate/core.rs":"8087c155cb47f57a9747565857dcef59fff0a7a499abbfdb0c60e694d3234db8","src/deflate/mod.rs":"8ade5b9683b8d728fe5e8f5c23e0630165bfdbef3e56a18b1b729f9bbd4a4b1d","src/deflate/stream.rs":"016c82b09a989492c8c8ea89027d339fcf59a5ca2155e7026ac094ca74344712","src/inflate/core.rs":"49bd596d5255ac88b486f6f978ab7b26663cdab01a6ebaa41bf4559f12b0fed8","src/inflate/mod.rs":"690a8cd50a7da88672b750bb2c62d52d2a58efa41e6ddb2084589a17095cb875","src/inflate/output_buffer.rs":"1ae90d03ba8c9d667fe248b6066731774afdf93cc79cd3bf90e0711b963b0b72","src/inflate/stream.rs":"f82c44ffdff054aff05307ed5709e432b54d5997bb4bbfff8f760171c33c76c3","src/lib.rs":"a9d6a889415ffe3d800c8516fb0ac0bae3585010966d1fdf3b06a85330c36854","src/shared.rs":"a8c47fcb566591e39fcd50d44f3b4d0f567318b8ca36c8d732ee0d8c99a14906"},"package":"96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34"} \ No newline at end of file
+{"files":{"Cargo.toml":"1a05b1f1b1cee9093e2d261931b86dcd92057289d5d8cd675381df52e029c797","LICENSE":"e190940e8ad3cdd4fca962a6508ed6865d589d314b1cb055f86000e124b88d8d","LICENSE-APACHE.md":"0d542e0c8804e39aa7f37eb00da5a762149dc682d7829451287e11b938e94594","LICENSE-MIT.md":"e190940e8ad3cdd4fca962a6508ed6865d589d314b1cb055f86000e124b88d8d","LICENSE-ZLIB.md":"c89bcc058da12a0fb24402b8ea4542a21515dd1da2e8c67bba4ed9bd269f1c96","Readme.md":"d9ae0e4192de8809293672397459f90bdb3cc6a6bd92f235edafbb0530181efb","src/deflate/buffer.rs":"76bcca4e79bef412eeebdd06d2d0a4348ed9ee17edbdaa6d451d8bf03b1cde85","src/deflate/core.rs":"8087c155cb47f57a9747565857dcef59fff0a7a499abbfdb0c60e694d3234db8","src/deflate/mod.rs":"8ade5b9683b8d728fe5e8f5c23e0630165bfdbef3e56a18b1b729f9bbd4a4b1d","src/deflate/stream.rs":"016c82b09a989492c8c8ea89027d339fcf59a5ca2155e7026ac094ca74344712","src/inflate/core.rs":"e7b8946db6a56834311b382fa1f8a3aba21a9ca42cf880c4ae1c97f699d22092","src/inflate/mod.rs":"6a6f658cd44c47f1ba402328fb78c27b24b8700a909ddac4c0c472b12046d1fa","src/inflate/output_buffer.rs":"1ae90d03ba8c9d667fe248b6066731774afdf93cc79cd3bf90e0711b963b0b72","src/inflate/stream.rs":"b1d96270d89b549bdc09352bfbd5a4fea24b479c0057c1f50b66b30ce2eb9cc1","src/lib.rs":"7cb7c0ebc61141f0e43a6edca97a22c93ca3b1550893007359007d4dfdeaa883","src/shared.rs":"a8c47fcb566591e39fcd50d44f3b4d0f567318b8ca36c8d732ee0d8c99a14906"},"package":"b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa"} \ No newline at end of file
diff --git a/vendor/miniz_oxide/Cargo.toml b/vendor/miniz_oxide/Cargo.toml
index 7fa9d3e06..bbb3e9adb 100644
--- a/vendor/miniz_oxide/Cargo.toml
+++ b/vendor/miniz_oxide/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "miniz_oxide"
-version = "0.5.4"
+version = "0.6.2"
authors = [
"Frommi <daniil.liferenko@gmail.com>",
"oyvindln <oyvindln@users.noreply.github.com>",
@@ -62,7 +62,7 @@ optional = true
default-features = false
[features]
-default = []
+default = ["with-alloc"]
rustc-dep-of-std = [
"core",
"alloc",
@@ -70,3 +70,5 @@ rustc-dep-of-std = [
"adler/rustc-dep-of-std",
]
simd = ["simd-adler32"]
+std = []
+with-alloc = []
diff --git a/vendor/miniz_oxide/Readme.md b/vendor/miniz_oxide/Readme.md
index 0eac176e8..51579f071 100644
--- a/vendor/miniz_oxide/Readme.md
+++ b/vendor/miniz_oxide/Readme.md
@@ -3,9 +3,18 @@
A fully safe, pure rust replacement for the [miniz](https://github.com/richgel999/miniz) DEFLATE/zlib encoder/decoder.
The main intention of this crate is to be used as a back-end for the [flate2](https://github.com/alexcrichton/flate2-rs), but it can also be used on it's own. Using flate2 with the ```rust_backend``` feature provides an easy to use streaming API for miniz_oxide.
-The library is fully [no_std](https://docs.rust-embedded.org/book/intro/no-std.html), though it requires the use of the `alloc` and `collection` crates as it allocates memory.
+The library is fully [no_std](https://docs.rust-embedded.org/book/intro/no-std.html). By default, the `with-alloc` feature is enabled, which requires the use of the `alloc` and `collection` crates as it allocates memory.
-miniz_oxide 0.5.x Requires at least rust 1.40.0 0.3.x requires at least rust 0.36.0.
+The `std` feature additionally turns on things only available if `no_std` is not used. Currently this only means implementing [Error](https://doc.rust-lang.org/stable/std/error/trait.Error.html) for the `DecompressError` error struct returned by the simple decompression functions if enabled together with `with-alloc`.
+
+Using the library with `default-features = false` removes the dependency on `alloc`
+and `collection` crates, making it suitable for systems without an allocator.
+Running without allocation reduces crate functionality:
+
+- The `deflate` module is removed complete
+- Some `inflate` functions which return a `Vec` are removed
+
+miniz_oxide 0.5.x and 0.6.x Requires at least rust 1.40.0 0.3.x requires at least rust 0.36.0.
miniz_oxide features no use of unsafe code.
@@ -21,8 +30,8 @@ use miniz_oxide::inflate::decompress_to_vec;
fn roundtrip(data: &[u8]) {
// Compress the input
let compressed = compress_to_vec(data, 6);
- // Decompress the compressed input
- let decompressed = decompress_to_vec(compressed.as_slice()).expect("Failed to decompress!");
+ // Decompress the compressed input and limit max output size to avoid going out of memory on large/malformed input.
+ let decompressed = decompress_to_vec_with_limit(compressed.as_slice(), 60000).expect("Failed to decompress!");
// Check roundtrip succeeded
assert_eq!(data, decompressed);
}
@@ -32,4 +41,4 @@ fn main() {
}
```
-These simple functions will do everything in one go and are thus not recommended for use cases where the input size may be large or unknown, for that use case consider using miniz_oxide via flate2 or the low-level streaming functions instead.
+These simple functions will do everything in one go and are thus not recommended for use cases outside of prototyping/testing as real world data can have any size and thus result in very large memory allocations for the output Vector. Consider using miniz_oxide via [flate2](https://github.com/alexcrichton/flate2-rs) which makes it easy to do streaming (de)compression or the low-level streaming functions instead.
diff --git a/vendor/miniz_oxide/src/inflate/core.rs b/vendor/miniz_oxide/src/inflate/core.rs
index 38bdacbbd..630e5e6fd 100644
--- a/vendor/miniz_oxide/src/inflate/core.rs
+++ b/vendor/miniz_oxide/src/inflate/core.rs
@@ -108,7 +108,7 @@ const HUFFLEN_TABLE: usize = 2;
pub mod inflate_flags {
/// Should we try to parse a zlib header?
///
- /// If unset, [`decompress()`] will expect an RFC1951 deflate stream. If set, it will expect an
+ /// If unset, the function will expect an RFC1951 deflate stream. If set, it will expect a
/// RFC1950 zlib wrapper around the deflate stream.
pub const TINFL_FLAG_PARSE_ZLIB_HEADER: u32 = 1;
@@ -1456,7 +1456,8 @@ pub fn decompress(
// Mask the top bits since they may contain length info.
l.counter &= 511;
- if l.counter == 256 {
+ if l.counter
+ == 256 {
// We hit the end of block symbol.
Action::Jump(BlockDone)
} else if l.counter > 285 {
diff --git a/vendor/miniz_oxide/src/inflate/mod.rs b/vendor/miniz_oxide/src/inflate/mod.rs
index 03b9dc988..bb19e379c 100644
--- a/vendor/miniz_oxide/src/inflate/mod.rs
+++ b/vendor/miniz_oxide/src/inflate/mod.rs
@@ -1,10 +1,10 @@
//! This module contains functionality for decompression.
-use crate::alloc::boxed::Box;
-use crate::alloc::vec;
-use crate::alloc::vec::Vec;
-use ::core::cmp::min;
+#[cfg(feature = "with-alloc")]
+use crate::alloc::{boxed::Box, vec, vec::Vec};
use ::core::usize;
+#[cfg(all(feature = "std", feature = "with-alloc"))]
+use std::error::Error;
pub mod core;
mod output_buffer;
@@ -78,19 +78,63 @@ impl TINFLStatus {
}
}
+/// Struct return when decompress_to_vec functions fail.
+#[cfg(feature = "with-alloc")]
+#[derive(Debug)]
+pub struct DecompressError {
+ /// Decompressor status on failure. See [TINFLStatus] for details.
+ pub status: TINFLStatus,
+ /// The currently decompressed data if any.
+ pub output: Vec<u8>,
+}
+
+#[cfg(feature = "with-alloc")]
+impl alloc::fmt::Display for DecompressError {
+ fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
+ f.write_str(match self.status {
+ TINFLStatus::FailedCannotMakeProgress => "Truncated input stream",
+ TINFLStatus::BadParam => "Invalid output buffer size",
+ TINFLStatus::Adler32Mismatch => "Adler32 checksum mismatch",
+ TINFLStatus::Failed => "Invalid input data",
+ TINFLStatus::Done => unreachable!(),
+ TINFLStatus::NeedsMoreInput => "Truncated input stream",
+ TINFLStatus::HasMoreOutput => "Output size exceeded the specified limit",
+ })
+ }
+}
+
+/// Implement Error trait only if std feature is requested as it requires std.
+#[cfg(all(feature = "std", feature = "with-alloc"))]
+impl Error for DecompressError {}
+
+#[cfg(feature = "with-alloc")]
+fn decompress_error(status: TINFLStatus, output: Vec<u8>) -> Result<Vec<u8>, DecompressError> {
+ Err(DecompressError { status, output })
+}
+
/// Decompress the deflate-encoded data in `input` to a vector.
///
-/// Returns a tuple of the [`Vec`] of decompressed data and the [status result][TINFLStatus].
+/// NOTE: This function will not bound the output, so if the output is large enough it can result in an out of memory error.
+/// It is therefore suggested to not use this for anything other than test programs, use the functions with a specified limit, or
+/// ideally streaming decompression via the [flate2](https://github.com/alexcrichton/flate2-rs) library instead.
+///
+/// Returns a [`Result`] containing the [`Vec`] of decompressed data on success, and a [struct][DecompressError] containing the status and so far decompressed data if any on failure.
#[inline]
-pub fn decompress_to_vec(input: &[u8]) -> Result<Vec<u8>, TINFLStatus> {
+#[cfg(feature = "with-alloc")]
+pub fn decompress_to_vec(input: &[u8]) -> Result<Vec<u8>, DecompressError> {
decompress_to_vec_inner(input, 0, usize::max_value())
}
/// Decompress the deflate-encoded data (with a zlib wrapper) in `input` to a vector.
///
-/// Returns a tuple of the [`Vec`] of decompressed data and the [status result][TINFLStatus].
+/// NOTE: This function will not bound the output, so if the output is large enough it can result in an out of memory error.
+/// It is therefore suggested to not use this for anything other than test programs, use the functions with a specified limit, or
+/// ideally streaming decompression via the [flate2](https://github.com/alexcrichton/flate2-rs) library instead.
+///
+/// Returns a [`Result`] containing the [`Vec`] of decompressed data on success, and a [struct][DecompressError] containing the status and so far decompressed data if any on failure.
#[inline]
-pub fn decompress_to_vec_zlib(input: &[u8]) -> Result<Vec<u8>, TINFLStatus> {
+#[cfg(feature = "with-alloc")]
+pub fn decompress_to_vec_zlib(input: &[u8]) -> Result<Vec<u8>, DecompressError> {
decompress_to_vec_inner(
input,
inflate_flags::TINFL_FLAG_PARSE_ZLIB_HEADER,
@@ -99,38 +143,51 @@ pub fn decompress_to_vec_zlib(input: &[u8]) -> Result<Vec<u8>, TINFLStatus> {
}
/// Decompress the deflate-encoded data in `input` to a vector.
+///
/// The vector is grown to at most `max_size` bytes; if the data does not fit in that size,
-/// [`TINFLStatus::HasMoreOutput`] error is returned.
+/// the error [struct][DecompressError] will contain the status [`TINFLStatus::HasMoreOutput`] and the data that was decompressed on failure.
+///
+/// As this function tries to decompress everything in one go, it's not ideal for general use outside of tests or where the output size is expected to be small.
+/// It is suggested to use streaming decompression via the [flate2](https://github.com/alexcrichton/flate2-rs) library instead.
///
-/// Returns a tuple of the [`Vec`] of decompressed data and the [status result][TINFLStatus].
+/// Returns a [`Result`] containing the [`Vec`] of decompressed data on success, and a [struct][DecompressError] on failure.
#[inline]
-pub fn decompress_to_vec_with_limit(input: &[u8], max_size: usize) -> Result<Vec<u8>, TINFLStatus> {
+#[cfg(feature = "with-alloc")]
+pub fn decompress_to_vec_with_limit(
+ input: &[u8],
+ max_size: usize,
+) -> Result<Vec<u8>, DecompressError> {
decompress_to_vec_inner(input, 0, max_size)
}
/// Decompress the deflate-encoded data (with a zlib wrapper) in `input` to a vector.
/// The vector is grown to at most `max_size` bytes; if the data does not fit in that size,
-/// [`TINFLStatus::HasMoreOutput`] error is returned.
+/// the error [struct][DecompressError] will contain the status [`TINFLStatus::HasMoreOutput`] and the data that was decompressed on failure.
+///
+/// As this function tries to decompress everything in one go, it's not ideal for general use outside of tests or where the output size is expected to be small.
+/// It is suggested to use streaming decompression via the [flate2](https://github.com/alexcrichton/flate2-rs) library instead.
///
-/// Returns a tuple of the [`Vec`] of decompressed data and the [status result][TINFLStatus].
+/// Returns a [`Result`] containing the [`Vec`] of decompressed data on success, and a [struct][DecompressError] on failure.
#[inline]
+#[cfg(feature = "with-alloc")]
pub fn decompress_to_vec_zlib_with_limit(
input: &[u8],
max_size: usize,
-) -> Result<Vec<u8>, TINFLStatus> {
+) -> Result<Vec<u8>, DecompressError> {
decompress_to_vec_inner(input, inflate_flags::TINFL_FLAG_PARSE_ZLIB_HEADER, max_size)
}
/// Backend of various to-[`Vec`] decompressions.
///
-/// Returns a tuple of the [`Vec`] of decompressed data and the [status result][TINFLStatus].
+/// Returns [`Vec`] of decompressed data on success and the [error struct][DecompressError] with details on failure.
+#[cfg(feature = "with-alloc")]
fn decompress_to_vec_inner(
input: &[u8],
flags: u32,
max_output_size: usize,
-) -> Result<Vec<u8>, TINFLStatus> {
+) -> Result<Vec<u8>, DecompressError> {
let flags = flags | inflate_flags::TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
- let mut ret: Vec<u8> = vec![0; min(input.len().saturating_mul(2), max_output_size)];
+ let mut ret: Vec<u8> = vec![0; input.len().saturating_mul(2).min(max_output_size)];
let mut decomp = Box::<DecompressorOxide>::default();
@@ -153,14 +210,14 @@ fn decompress_to_vec_inner(
TINFLStatus::HasMoreOutput => {
// if the buffer has already reached the size limit, return an error
if ret.len() >= max_output_size {
- return Err(TINFLStatus::HasMoreOutput);
+ return decompress_error(TINFLStatus::HasMoreOutput, ret);
}
// calculate the new length, capped at `max_output_size`
let new_len = ret.len().saturating_mul(2).min(max_output_size);
ret.resize(new_len, 0);
}
- _ => return Err(status),
+ _ => return decompress_error(status, ret),
}
}
}
@@ -221,7 +278,7 @@ pub fn decompress_slice_iter_to_slice<'out, 'inp>(
mod test {
use super::{
decompress_slice_iter_to_slice, decompress_to_vec_zlib, decompress_to_vec_zlib_with_limit,
- TINFLStatus,
+ DecompressError, TINFLStatus,
};
const ENCODED: [u8; 20] = [
120, 156, 243, 72, 205, 201, 201, 215, 81, 168, 202, 201, 76, 82, 4, 0, 27, 101, 4, 19,
@@ -243,7 +300,10 @@ mod test {
fn fail_to_decompress_with_limit() {
let res = decompress_to_vec_zlib_with_limit(&ENCODED[..], 8);
match res {
- Err(TINFLStatus::HasMoreOutput) => (), // expected result
+ Err(DecompressError {
+ status: TINFLStatus::HasMoreOutput,
+ ..
+ }) => (), // expected result
_ => panic!("Decompression output size limit was not enforced"),
}
}
diff --git a/vendor/miniz_oxide/src/inflate/stream.rs b/vendor/miniz_oxide/src/inflate/stream.rs
index 715747166..ee681b67b 100644
--- a/vendor/miniz_oxide/src/inflate/stream.rs
+++ b/vendor/miniz_oxide/src/inflate/stream.rs
@@ -1,6 +1,7 @@
//! Extra streaming decompression functionality.
//!
//! As of now this is mainly intended for use to build a higher-level wrapper.
+#[cfg(feature = "with-alloc")]
use crate::alloc::boxed::Box;
use core::{cmp, mem};
@@ -115,6 +116,7 @@ impl InflateState {
/// # Parameters
/// `data_format`: Determines whether the compressed data is assumed to wrapped with zlib
/// metadata.
+ #[cfg(feature = "with-alloc")]
pub fn new_boxed(data_format: DataFormat) -> Box<InflateState> {
let mut b: Box<InflateState> = Box::default();
b.data_format = data_format;
@@ -136,6 +138,7 @@ impl InflateState {
/// The decompressor does not support different window sizes. As such,
/// any positive (>0) value will set the zlib header flag, while a negative one
/// will not.
+ #[cfg(feature = "with-alloc")]
pub fn new_boxed_with_window_bits(window_bits: i32) -> Box<InflateState> {
let mut b: Box<InflateState> = Box::default();
b.data_format = DataFormat::from_window_bits(window_bits);
diff --git a/vendor/miniz_oxide/src/lib.rs b/vendor/miniz_oxide/src/lib.rs
index 8357c5200..fd64932b0 100644
--- a/vendor/miniz_oxide/src/lib.rs
+++ b/vendor/miniz_oxide/src/lib.rs
@@ -22,10 +22,12 @@
//! ```
#![forbid(unsafe_code)]
-#![no_std]
+#![cfg_attr(not(feature = "std"), no_std)]
+#[cfg(feature = "with-alloc")]
extern crate alloc;
+#[cfg(feature = "with-alloc")]
pub mod deflate;
pub mod inflate;
mod shared;
@@ -154,7 +156,7 @@ pub enum DataFormat {
}
impl DataFormat {
- pub(crate) fn from_window_bits(window_bits: i32) -> DataFormat {
+ pub fn from_window_bits(window_bits: i32) -> DataFormat {
if window_bits > 0 {
DataFormat::Zlib
} else {
@@ -162,7 +164,7 @@ impl DataFormat {
}
}
- pub(crate) fn to_window_bits(self) -> i32 {
+ pub fn to_window_bits(self) -> i32 {
match self {
DataFormat::Zlib | DataFormat::ZLibIgnoreChecksum => shared::MZ_DEFAULT_WINDOW_BITS,
DataFormat::Raw => -shared::MZ_DEFAULT_WINDOW_BITS,
@@ -186,7 +188,7 @@ pub struct StreamResult {
impl StreamResult {
#[inline]
- pub(crate) const fn error(error: MZError) -> StreamResult {
+ pub const fn error(error: MZError) -> StreamResult {
StreamResult {
bytes_consumed: 0,
bytes_written: 0,