File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -864,7 +864,19 @@ fn mainSort(
864864 let bbStart = ftab[ ( ss as usize ) << 8 ] & CLEARMASK ;
865865 let bbSize = ( ftab[ ( ss as usize + 1 ) << 8 ] & CLEARMASK ) as i32 - bbStart as i32 ;
866866
867- let shifts = ( bbSize >> 16 ) . count_ones ( ) ;
867+ // FIXME: remove when our MSRV can use the stable method.
868+ fn highest_one ( x : i32 ) -> Option < u32 > {
869+ match x {
870+ 0 => None ,
871+ _ => Some ( i32:: BITS - 1 - x. leading_zeros ( ) ) ,
872+ }
873+ }
874+
875+ let shifts = if bbSize <= 65_534 {
876+ 0
877+ } else {
878+ highest_one ( bbSize) . unwrap ( ) - 15
879+ } ;
868880
869881 let ptr = & ptr[ bbStart as usize ..] [ ..bbSize as usize ] ;
870882 for j in ( 0 ..bbSize) . rev ( ) {
Original file line number Diff line number Diff line change @@ -238,6 +238,13 @@ fn compress_sample1() {
238238 assert_eq_compress ! ( "../../tests/input/quick/sample1.bz2" ) ;
239239}
240240
241+ #[ test]
242+ fn issue_137 ( ) {
243+ // Exposed a logic error in blocksort.
244+ // See https://github.com/trifectatechfoundation/libbzip2-rs/issues/137.
245+ assert_eq_compress ! ( "../../tests/input/issue_137.bin" ) ;
246+ }
247+
241248#[ test]
242249fn compress_sample2 ( ) {
243250 assert_eq_compress ! ( "../../tests/input/quick/sample2.bz2" ) ;
You can’t perform that action at this time.
0 commit comments