Set default strip size to 1MB

This commit is contained in:
Robert Wassens committed 2020-12-07 11:44:21 +01:00
1 parent 5346a441ae
commit 3e042df438
1 file changed
+5 -3
+5 -3
View File
@@ -623,10 +623,11 @@ impl<'a, W: 'a + Write + Seek, T: ColorType> ImageEncoder<'a, W, T> {
height: u32, height: u32,
) -> TiffResult<ImageEncoder<'a, W, T>> { ) -> TiffResult<ImageEncoder<'a, W, T>> {
let row_samples = u64::from(width) * u64::try_from(<T>::BITS_PER_SAMPLE.len())?; let row_samples = u64::from(width) * u64::try_from(<T>::BITS_PER_SAMPLE.len())?;
let row_bytes = row_samples * u64::from(<T::Inner>::BYTE_LEN);
// By default write the image as single strip. This can be changed by calling // Limit the strip size to prevent potential memory and security issues.
// rows_per_strip() before the first data is written. // Also keep the multiple strip handling 'oiled'
let rows_per_strip = height as u64; let rows_per_strip = (1_000_000 + row_bytes - 1) / row_bytes;
let strip_count = (u64::from(height) + rows_per_strip - 1) / rows_per_strip; let strip_count = (u64::from(height) + rows_per_strip - 1) / rows_per_strip;
@@ -760,6 +761,7 @@ impl<'a, W: 'a + Write + Seek, T: ColorType> ImageEncoder<'a, W, T> {
/// Set image number of lines per strip /// Set image number of lines per strip
/// ///
/// This function needs to be called before any calls to `write_data` or
/// `write_strip` and will return an error otherwise. /// `write_strip` and will return an error otherwise.
pub fn rows_per_strip(&mut self, value: u32) -> TiffResult<()> { pub fn rows_per_strip(&mut self, value: u32) -> TiffResult<()> {
if self.strip_idx != 0 { if self.strip_idx != 0 {