@@ -442,8 +442,8 @@ impl super::Engine for AVX2Encoder {
442442 // FIXME: Prove this is correct or remove it. Doing an extra fast loop over two bytes
443443 // is not worth violating safety.
444444 // 11 => 11,
445- x if x < 14 => ( BLOCKS_PER_FAST_LOOP * 8 ) + x,
446- x if x >= 14 => x,
445+ x if x <= 12 => ( BLOCKS_PER_FAST_LOOP * 8 ) + x,
446+ x if x > 12 => x,
447447 _ => unreachable ! ( "Maths, how does it work?" ) ,
448448 } ;
449449
@@ -488,6 +488,9 @@ impl super::Engine for AVX2Encoder {
488488 // happen is test code that knowingly provides both invalid data and an undersized
489489 // buffer assuming linear decoding that breaks off as soon as it hits this invalid
490490 // data.
491+ if output. len ( ) -output_index < 32 {
492+ println ! ( "IL {} OL {}" , input. len( ) , output. len( ) ) ;
493+ }
491494 let output_chunk = & mut output[ output_index..( output_index + 32 ) ] ;
492495
493496
@@ -788,6 +791,7 @@ impl Config for AVX2Config {
788791#[ cfg( test) ]
789792mod tests {
790793 use super :: * ;
794+ use crate :: decode:: decode_engine;
791795
792796 #[ test]
793797 fn maskload_array_is_sane ( ) {
@@ -801,4 +805,20 @@ mod tests {
801805 assert_eq ! ( & MASKLOAD [ 7 ..15 ] , & [ -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
802806 assert_eq ! ( & MASKLOAD [ 8 ..16 ] , & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
803807 }
808+
809+ #[ test]
810+ fn test_every_len ( ) {
811+ let engine = AVX2Encoder :: from_standard ( AVX2Config :: new ( ) ) ;
812+ let mut v = Vec :: with_capacity ( 8192 ) ;
813+ for i in 1 ..8192 {
814+ v. push ( 'A' as u8 ) ;
815+ let r = decode_engine ( & v, & engine) ;
816+ match i % 4 {
817+ 1 => assert_eq ! ( r, Err ( DecodeError :: InvalidLength ) ) ,
818+ x => {
819+ assert_eq ! ( r. unwrap( ) . len( ) , i* 3 /4 , "Failed on len {}" , x) ;
820+ } ,
821+ }
822+ }
823+ }
804824}
0 commit comments