summaryrefslogtreecommitdiffstats
path: root/decoder.h
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 11:45:06 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 11:45:06 +0000
commit1ed437c55879912627b4f4fcd02cf07866cb48bb (patch)
treef418c22c84311ba379b907dd2bcf317ddb08a239 /decoder.h
parentAdding upstream version 1.15. (diff)
downloadlziprecover-1ed437c55879912627b4f4fcd02cf07866cb48bb.tar.xz
lziprecover-1ed437c55879912627b4f4fcd02cf07866cb48bb.zip
Adding upstream version 1.16~pre1.upstream/1.16_pre1
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'decoder.h')
-rw-r--r--decoder.h43
1 files changed, 25 insertions, 18 deletions
diff --git a/decoder.h b/decoder.h
index 1269728..4230c5a 100644
--- a/decoder.h
+++ b/decoder.h
@@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for lzip files
- Copyright (C) 2009, 2010, 2011, 2012, 2013 Antonio Diaz Diaz.
+ Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -76,6 +76,7 @@ public:
code = 0;
for( int i = 0; i < 5; ++i ) code = (code << 8) | get_byte();
range = 0xFFFFFFFFU;
+ code &= range; // make sure that first byte is discarded
}
void normalize()
@@ -120,12 +121,13 @@ public:
}
}
- int decode_tree( Bit_model bm[], const int num_bits )
+ int decode_tree3( Bit_model bm[] )
{
int symbol = 1;
- for( int i = num_bits; i > 0; --i )
- symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
- return symbol - (1 << num_bits);
+ symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
+ symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
+ symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
+ return symbol & 7;
}
int decode_tree6( Bit_model bm[] )
@@ -137,7 +139,15 @@ public:
symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
- return symbol - (1 << 6);
+ return symbol & 0x3F;
+ }
+
+ int decode_tree8( Bit_model bm[] )
+ {
+ int symbol = 1;
+ while( symbol < 0x100 )
+ symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
+ return symbol & 0xFF;
}
int decode_tree_reversed( Bit_model bm[], const int num_bits )
@@ -156,10 +166,9 @@ public:
int decode_tree_reversed4( Bit_model bm[] )
{
int model = 1;
- int symbol = 0;
+ int symbol = decode_bit( bm[model] );
+ model = (model << 1) + symbol;
int bit = decode_bit( bm[model] );
- model = (model << 1) + bit; symbol |= bit;
- bit = decode_bit( bm[model] );
model = (model << 1) + bit; symbol |= (bit << 1);
bit = decode_bit( bm[model] );
model = (model << 1) + bit; symbol |= (bit << 2);
@@ -171,7 +180,7 @@ public:
{
Bit_model * const bm1 = bm + 0x100;
int symbol = 1;
- for( int i = 7; i >= 0; --i )
+ while( symbol < 0x100 )
{
match_byte <<= 1;
const int match_bit = match_byte & 0x100;
@@ -184,18 +193,16 @@ public:
break;
}
}
- return symbol - 0x100;
+ return symbol & 0xFF;
}
int decode_len( Len_model & lm, const int pos_state )
{
if( decode_bit( lm.choice1 ) == 0 )
- return decode_tree( lm.bm_low[pos_state], len_low_bits );
+ return decode_tree3( lm.bm_low[pos_state] );
if( decode_bit( lm.choice2 ) == 0 )
- return len_low_symbols +
- decode_tree( lm.bm_mid[pos_state], len_mid_bits );
- return len_low_symbols + len_mid_symbols +
- decode_tree( lm.bm_high, len_high_bits );
+ return len_low_symbols + decode_tree3( lm.bm_mid[pos_state] );
+ return len_low_symbols + len_mid_symbols + decode_tree8( lm.bm_high );
}
};
@@ -206,7 +213,7 @@ class LZ_decoder
const unsigned long long outend;
unsigned long long partial_data_pos;
Range_decoder & rdec;
- const int dictionary_size;
+ const unsigned dictionary_size;
const int buffer_size;
uint8_t * const buffer; // output buffer
int pos; // current pos in buffer
@@ -268,7 +275,7 @@ public:
partial_data_pos( 0 ),
rdec( rde ),
dictionary_size( header.dictionary_size() ),
- buffer_size( std::max( 65536, dictionary_size ) ),
+ buffer_size( std::max( 65536U, dictionary_size ) ),
buffer( new uint8_t[buffer_size] ),
pos( 0 ),
stream_pos( 0 ),