@@ -206,6 +206,7 @@ pub enum ChunkType {
206206
207207/// Decoding limits
208208#[ derive( Clone , Debug ) ]
209+ #[ non_exhaustive]
209210pub struct Limits {
210211 /// The maximum size of any `DecodingResult` in bytes, the default is
211212 /// 256MiB. If the entire image is decoded at once, then this will
@@ -218,10 +219,6 @@ pub struct Limits {
218219 /// Maximum size for intermediate buffer which may be used to limit the amount of data read per
219220 /// segment even if the entire image is decoded at once.
220221 pub intermediate_buffer_size : usize ,
221- /// The purpose of this is to prevent all the fields of the struct from
222- /// being public, as this would make adding new fields a major version
223- /// bump.
224- _non_exhaustive : ( ) ,
225222}
226223
227224impl Limits {
@@ -234,10 +231,9 @@ impl Limits {
234231 /// naturally, the machine running the program does not have infinite memory.
235232 pub fn unlimited ( ) -> Limits {
236233 Limits {
237- decoding_buffer_size : usize:: max_value ( ) ,
238- ifd_value_size : usize:: max_value ( ) ,
239- intermediate_buffer_size : usize:: max_value ( ) ,
240- _non_exhaustive : ( ) ,
234+ decoding_buffer_size : usize:: MAX ,
235+ ifd_value_size : usize:: MAX ,
236+ intermediate_buffer_size : usize:: MAX ,
241237 }
242238 }
243239}
@@ -248,7 +244,6 @@ impl Default for Limits {
248244 decoding_buffer_size : 256 * 1024 * 1024 ,
249245 intermediate_buffer_size : 128 * 1024 * 1024 ,
250246 ifd_value_size : 1024 * 1024 ,
251- _non_exhaustive : ( ) ,
252247 }
253248 }
254249}
@@ -861,7 +856,8 @@ impl<R: Read + Seek> Decoder<R> {
861856 let row_samples = if bits_per_sample >= 8 {
862857 width
863858 } else {
864- ( ( ( ( width as u64 ) * bits_per_sample as u64 ) + 7 ) / 8 )
859+ ( ( width as u64 ) * bits_per_sample as u64 )
860+ . div_ceil ( 8 )
865861 . try_into ( )
866862 . map_err ( |_| TiffError :: LimitsExceeded ) ?
867863 } ;
@@ -960,12 +956,12 @@ impl<R: Read + Seek> Decoder<R> {
960956 let output_row_bits = ( width as u64 * self . image . bits_per_sample as u64 )
961957 . checked_mul ( samples as u64 )
962958 . ok_or ( TiffError :: LimitsExceeded ) ?;
963- let output_row_stride: usize = ( ( output_row_bits + 7 ) / 8 ) . try_into ( ) ?;
959+ let output_row_stride: usize = output_row_bits. div_ceil ( 8 ) . try_into ( ) ?;
964960
965961 let chunk_row_bits = ( chunk_dimensions. 0 as u64 * self . image . bits_per_sample as u64 )
966962 . checked_mul ( samples as u64 )
967963 . ok_or ( TiffError :: LimitsExceeded ) ?;
968- let chunk_row_bytes: usize = ( ( chunk_row_bits + 7 ) / 8 ) . try_into ( ) ?;
964+ let chunk_row_bytes: usize = chunk_row_bits. div_ceil ( 8 ) . try_into ( ) ?;
969965
970966 let chunks_across = ( ( width - 1 ) / chunk_dimensions. 0 + 1 ) as usize ;
971967
0 commit comments