Change implementation details for InflateError, add uncompressed cap
This commit is contained in:
1 parent
6f9f2adfbf
commit
f8d4b57120
3 files changed
+21
-10
No files matched your search
+1
-1
@@ -580,7 +580,7 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
(bytes, Box::new(reader))
|
||||
}
|
||||
CompressionMethod::OldDeflate => {
|
||||
let (bytes, reader) = DeflateReader::new(&mut self.reader)?;
|
||||
let (bytes, reader) = DeflateReader::new(&mut self.reader, max_uncompressed_length)?;
|
||||
(bytes, Box::new(reader))
|
||||
}
|
||||
method => {
|
||||
|
||||
+14
-3
@@ -1,6 +1,6 @@
|
||||
//! All IO functionality needed for TIFF decoding
|
||||
|
||||
use crate::error::TiffResult;
|
||||
use crate::error::{TiffError, TiffResult};
|
||||
use byteorder::{BigEndian, LittleEndian, ReadBytesExt};
|
||||
use lzw;
|
||||
use miniz_oxide::inflate;
|
||||
@@ -76,11 +76,22 @@ pub struct DeflateReader {
|
||||
}
|
||||
|
||||
impl DeflateReader {
|
||||
pub fn new<R: Read + Seek>(reader: &mut SmartReader<R>) -> TiffResult<(usize, Self)> {
|
||||
pub fn new<R: Read + Seek>(
|
||||
reader: &mut SmartReader<R>,
|
||||
max_uncompressed_length: usize,
|
||||
) -> TiffResult<(usize, Self)> {
|
||||
let byte_order = reader.byte_order;
|
||||
let mut compressed = Vec::new();
|
||||
reader.read_to_end(&mut compressed)?;
|
||||
let uncompressed = inflate::decompress_to_vec_zlib(&compressed)?;
|
||||
|
||||
// TODO: Implement streaming compression, and remove this (temporary) and somewhat
|
||||
// misleading workaround.
|
||||
if compressed.len() > max_uncompressed_length {
|
||||
return Err(TiffError::LimitsExceeded);
|
||||
}
|
||||
|
||||
let uncompressed =
|
||||
inflate::decompress_to_vec_zlib(&compressed).map_err(TiffError::from_inflate_status)?;
|
||||
|
||||
Ok((
|
||||
uncompressed.len(),
|
||||
|
||||
+6
-6
@@ -67,15 +67,15 @@ pub struct InflateError {
|
||||
status: TINFLStatus,
|
||||
}
|
||||
|
||||
impl From<TINFLStatus> for TiffFormatError {
|
||||
fn from(status: TINFLStatus) -> Self {
|
||||
TiffFormatError::InflateError(InflateError { status })
|
||||
impl InflateError {
|
||||
pub fn new(status: TINFLStatus) -> Self {
|
||||
Self { status }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TINFLStatus> for TiffError {
|
||||
fn from(status: TINFLStatus) -> Self {
|
||||
TiffError::FormatError(status.into())
|
||||
impl TiffError {
|
||||
pub(crate) fn from_inflate_status(status: TINFLStatus) -> Self {
|
||||
TiffError::FormatError(TiffFormatError::InflateError(InflateError::new(status)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user