@@ -85,6 +85,7 @@ impl Compressor {
8585 let ( res, size) = f ( & mut self . inner , data, out_uninit) ;
8686 match res {
8787 CompressResult :: Success => {
88+ assert ! ( size <= bound) ;
8889 unsafe {
8990 output. set_len ( size) ;
9091 }
@@ -118,7 +119,10 @@ impl Compressor {
118119 let out_uninit = crate :: common:: slice_as_uninit_mut ( output) ;
119120 let ( res, size) = f ( & mut self . inner , data, out_uninit) ;
120121 match res {
121- CompressResult :: Success => Ok ( size) ,
122+ CompressResult :: Success => {
123+ assert ! ( size <= output. len( ) ) ;
124+ Ok ( size)
125+ }
122126 _ => Err ( io:: Error :: other ( error_msg) ) ,
123127 }
124128 }
@@ -233,6 +237,7 @@ impl Decompressor {
233237
234238 let ( res, _, size) = f ( & mut self . inner , data, out_uninit) ;
235239 if res == crate :: decompress:: DecompressResult :: Success {
240+ assert ! ( size <= expected_size) ;
236241 unsafe {
237242 output. set_len ( size) ;
238243 }
@@ -268,6 +273,7 @@ impl Decompressor {
268273 let out_uninit = crate :: common:: slice_as_uninit_mut ( output) ;
269274 let ( res, _, size) = f ( & mut self . inner , data, out_uninit) ;
270275 if res == crate :: decompress:: DecompressResult :: Success {
276+ assert ! ( size <= output. len( ) ) ;
271277 Ok ( size)
272278 } else {
273279 Err ( io:: Error :: new (
0 commit comments