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))
|
(bytes, Box::new(reader))
|
||||||
}
|
}
|
||||||
CompressionMethod::OldDeflate => {
|
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))
|
(bytes, Box::new(reader))
|
||||||
}
|
}
|
||||||
method => {
|
method => {
|
||||||
|
|||||||
+14
-3
@@ -1,6 +1,6 @@
|
|||||||
//! All IO functionality needed for TIFF decoding
|
//! All IO functionality needed for TIFF decoding
|
||||||
|
|
||||||
use crate::error::TiffResult;
|
use crate::error::{TiffError, TiffResult};
|
||||||
use byteorder::{BigEndian, LittleEndian, ReadBytesExt};
|
use byteorder::{BigEndian, LittleEndian, ReadBytesExt};
|
||||||
use lzw;
|
use lzw;
|
||||||
use miniz_oxide::inflate;
|
use miniz_oxide::inflate;
|
||||||
@@ -76,11 +76,22 @@ pub struct DeflateReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 byte_order = reader.byte_order;
|
||||||
let mut compressed = Vec::new();
|
let mut compressed = Vec::new();
|
||||||
reader.read_to_end(&mut compressed)?;
|
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((
|
Ok((
|
||||||
uncompressed.len(),
|
uncompressed.len(),
|
||||||
|
|||||||
+6
-6
@@ -67,15 +67,15 @@ pub struct InflateError {
|
|||||||
status: TINFLStatus,
|
status: TINFLStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<TINFLStatus> for TiffFormatError {
|
impl InflateError {
|
||||||
fn from(status: TINFLStatus) -> Self {
|
pub fn new(status: TINFLStatus) -> Self {
|
||||||
TiffFormatError::InflateError(InflateError { status })
|
Self { status }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<TINFLStatus> for TiffError {
|
impl TiffError {
|
||||||
fn from(status: TINFLStatus) -> Self {
|
pub(crate) fn from_inflate_status(status: TINFLStatus) -> Self {
|
||||||
TiffError::FormatError(status.into())
|
TiffError::FormatError(TiffFormatError::InflateError(InflateError::new(status)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user