Coverage Report

Created: 2026-09-28 07:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/lzma-rs-0.2.0/src/decode/lzma.rs
Line
Count
Source
1
use crate::decode::lzbuffer;
2
use crate::decode::rangecoder;
3
use crate::error;
4
use byteorder::{LittleEndian, ReadBytesExt};
5
use std::io;
6
use std::marker::PhantomData;
7
8
use crate::decompress::Options;
9
use crate::decompress::UnpackedSize;
10
11
/// Maximum input data that can be processed in one iteration.
12
/// Libhtp uses the following equation to define the maximum number of bits
13
/// for the worst case scenario:
14
///   log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160
15
const MAX_REQUIRED_INPUT: usize = 20;
16
17
/// Processing mode for decompression.
18
///
19
/// Tells the decompressor if we should expect more data after parsing the
20
/// current input.
21
#[derive(Debug, PartialEq)]
22
enum ProcessingMode {
23
    /// Streaming mode. Process the input bytes but assume there will be more
24
    /// chunks of input data to receive in future calls to `process_mode()`.
25
    Partial,
26
    /// Synchronous mode. Process the input bytes and confirm end of stream has been reached.
27
    /// Use this mode if you are processing a fixed buffer of compressed data, or after
28
    /// using `Mode::Partial` to check for the end of stream.
29
    Finish,
30
}
31
32
/// Result of the next iteration of processing.
33
///
34
/// Indicates whether processing should continue or is finished.
35
#[derive(Debug, PartialEq)]
36
enum ProcessingStatus {
37
    Continue,
38
    Finished,
39
}
40
41
pub struct LzmaParams {
42
    // most lc significant bits of previous byte are part of the literal context
43
    lc: u32, // 0..8
44
    lp: u32, // 0..4
45
    // context for literal/match is plaintext offset modulo 2^pb
46
    pb: u32, // 0..4
47
    dict_size: u32,
48
    unpacked_size: Option<u64>,
49
}
50
51
impl LzmaParams {
52
92.6k
    pub fn read_header<R>(input: &mut R, options: &Options) -> error::Result<LzmaParams>
53
92.6k
    where
54
92.6k
        R: io::BufRead,
55
    {
56
        // Properties
57
92.6k
        let props = input.read_u8().map_err(error::Error::HeaderTooShort)?;
58
59
92.6k
        let mut pb = props as u32;
60
92.6k
        if pb >= 225 {
61
7.45k
            return Err(error::Error::LzmaError(format!(
62
7.45k
                "LZMA header invalid properties: {} must be < 225",
63
7.45k
                pb
64
7.45k
            )));
65
85.1k
        }
66
67
85.1k
        let lc: u32 = pb % 9;
68
85.1k
        pb /= 9;
69
85.1k
        let lp: u32 = pb % 5;
70
85.1k
        pb /= 5;
71
72
        lzma_info!("Properties {{ lc: {}, lp: {}, pb: {} }}", lc, lp, pb);
73
74
        // Dictionary
75
85.1k
        let dict_size_provided = input
76
85.1k
            .read_u32::<LittleEndian>()
77
85.1k
            .map_err(error::Error::HeaderTooShort)?;
78
74.9k
        let dict_size = if dict_size_provided < 0x1000 {
79
3.06k
            0x1000
80
        } else {
81
71.8k
            dict_size_provided
82
        };
83
84
        lzma_info!("Dict size: {}", dict_size);
85
86
        // Unpacked size
87
74.9k
        let unpacked_size: Option<u64> = match options.unpacked_size {
88
            UnpackedSize::ReadFromHeader => {
89
74.9k
                let unpacked_size_provided = input
90
74.9k
                    .read_u64::<LittleEndian>()
91
74.9k
                    .map_err(error::Error::HeaderTooShort)?;
92
55.8k
                let marker_mandatory: bool = unpacked_size_provided == 0xFFFF_FFFF_FFFF_FFFF;
93
55.8k
                if marker_mandatory {
94
244
                    None
95
                } else {
96
55.6k
                    Some(unpacked_size_provided)
97
                }
98
            }
99
0
            UnpackedSize::ReadHeaderButUseProvided(x) => {
100
0
                input
101
0
                    .read_u64::<LittleEndian>()
102
0
                    .map_err(error::Error::HeaderTooShort)?;
103
0
                x
104
            }
105
0
            UnpackedSize::UseProvided(x) => x,
106
        };
107
108
        lzma_info!("Unpacked size: {:?}", unpacked_size);
109
110
55.8k
        let params = LzmaParams {
111
55.8k
            lc,
112
55.8k
            lp,
113
55.8k
            pb,
114
55.8k
            dict_size,
115
55.8k
            unpacked_size,
116
55.8k
        };
117
118
55.8k
        Ok(params)
119
92.6k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::LzmaParams>::read_header::<&mut std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::LzmaParams>::read_header::<_>
<lzma_rs::decode::lzma::LzmaParams>::read_header::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
52
6.20k
    pub fn read_header<R>(input: &mut R, options: &Options) -> error::Result<LzmaParams>
53
6.20k
    where
54
6.20k
        R: io::BufRead,
55
    {
56
        // Properties
57
6.20k
        let props = input.read_u8().map_err(error::Error::HeaderTooShort)?;
58
59
6.20k
        let mut pb = props as u32;
60
6.20k
        if pb >= 225 {
61
42
            return Err(error::Error::LzmaError(format!(
62
42
                "LZMA header invalid properties: {} must be < 225",
63
42
                pb
64
42
            )));
65
6.16k
        }
66
67
6.16k
        let lc: u32 = pb % 9;
68
6.16k
        pb /= 9;
69
6.16k
        let lp: u32 = pb % 5;
70
6.16k
        pb /= 5;
71
72
        lzma_info!("Properties {{ lc: {}, lp: {}, pb: {} }}", lc, lp, pb);
73
74
        // Dictionary
75
6.16k
        let dict_size_provided = input
76
6.16k
            .read_u32::<LittleEndian>()
77
6.16k
            .map_err(error::Error::HeaderTooShort)?;
78
6.10k
        let dict_size = if dict_size_provided < 0x1000 {
79
516
            0x1000
80
        } else {
81
5.58k
            dict_size_provided
82
        };
83
84
        lzma_info!("Dict size: {}", dict_size);
85
86
        // Unpacked size
87
6.10k
        let unpacked_size: Option<u64> = match options.unpacked_size {
88
            UnpackedSize::ReadFromHeader => {
89
6.10k
                let unpacked_size_provided = input
90
6.10k
                    .read_u64::<LittleEndian>()
91
6.10k
                    .map_err(error::Error::HeaderTooShort)?;
92
4.84k
                let marker_mandatory: bool = unpacked_size_provided == 0xFFFF_FFFF_FFFF_FFFF;
93
4.84k
                if marker_mandatory {
94
9
                    None
95
                } else {
96
4.83k
                    Some(unpacked_size_provided)
97
                }
98
            }
99
0
            UnpackedSize::ReadHeaderButUseProvided(x) => {
100
0
                input
101
0
                    .read_u64::<LittleEndian>()
102
0
                    .map_err(error::Error::HeaderTooShort)?;
103
0
                x
104
            }
105
0
            UnpackedSize::UseProvided(x) => x,
106
        };
107
108
        lzma_info!("Unpacked size: {:?}", unpacked_size);
109
110
4.84k
        let params = LzmaParams {
111
4.84k
            lc,
112
4.84k
            lp,
113
4.84k
            pb,
114
4.84k
            dict_size,
115
4.84k
            unpacked_size,
116
4.84k
        };
117
118
4.84k
        Ok(params)
119
6.20k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::LzmaParams>::read_header::<&mut std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::LzmaParams>::read_header::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
52
86.4k
    pub fn read_header<R>(input: &mut R, options: &Options) -> error::Result<LzmaParams>
53
86.4k
    where
54
86.4k
        R: io::BufRead,
55
    {
56
        // Properties
57
86.4k
        let props = input.read_u8().map_err(error::Error::HeaderTooShort)?;
58
59
86.4k
        let mut pb = props as u32;
60
86.4k
        if pb >= 225 {
61
7.41k
            return Err(error::Error::LzmaError(format!(
62
7.41k
                "LZMA header invalid properties: {} must be < 225",
63
7.41k
                pb
64
7.41k
            )));
65
79.0k
        }
66
67
79.0k
        let lc: u32 = pb % 9;
68
79.0k
        pb /= 9;
69
79.0k
        let lp: u32 = pb % 5;
70
79.0k
        pb /= 5;
71
72
        lzma_info!("Properties {{ lc: {}, lp: {}, pb: {} }}", lc, lp, pb);
73
74
        // Dictionary
75
79.0k
        let dict_size_provided = input
76
79.0k
            .read_u32::<LittleEndian>()
77
79.0k
            .map_err(error::Error::HeaderTooShort)?;
78
68.8k
        let dict_size = if dict_size_provided < 0x1000 {
79
2.54k
            0x1000
80
        } else {
81
66.2k
            dict_size_provided
82
        };
83
84
        lzma_info!("Dict size: {}", dict_size);
85
86
        // Unpacked size
87
68.8k
        let unpacked_size: Option<u64> = match options.unpacked_size {
88
            UnpackedSize::ReadFromHeader => {
89
68.8k
                let unpacked_size_provided = input
90
68.8k
                    .read_u64::<LittleEndian>()
91
68.8k
                    .map_err(error::Error::HeaderTooShort)?;
92
51.0k
                let marker_mandatory: bool = unpacked_size_provided == 0xFFFF_FFFF_FFFF_FFFF;
93
51.0k
                if marker_mandatory {
94
235
                    None
95
                } else {
96
50.8k
                    Some(unpacked_size_provided)
97
                }
98
            }
99
0
            UnpackedSize::ReadHeaderButUseProvided(x) => {
100
0
                input
101
0
                    .read_u64::<LittleEndian>()
102
0
                    .map_err(error::Error::HeaderTooShort)?;
103
0
                x
104
            }
105
0
            UnpackedSize::UseProvided(x) => x,
106
        };
107
108
        lzma_info!("Unpacked size: {:?}", unpacked_size);
109
110
51.0k
        let params = LzmaParams {
111
51.0k
            lc,
112
51.0k
            lp,
113
51.0k
            pb,
114
51.0k
            dict_size,
115
51.0k
            unpacked_size,
116
51.0k
        };
117
118
51.0k
        Ok(params)
119
86.4k
    }
120
}
121
122
pub struct DecoderState<W, LZB>
123
where
124
    W: io::Write,
125
    LZB: lzbuffer::LzBuffer<W>,
126
{
127
    _phantom: PhantomData<W>,
128
    // Buffer input data here if we need more for decompression. Up to
129
    // MAX_REQUIRED_INPUT bytes can be consumed during one iteration.
130
    partial_input_buf: std::io::Cursor<[u8; MAX_REQUIRED_INPUT]>,
131
    pub output: LZB,
132
    // most lc significant bits of previous byte are part of the literal context
133
    pub lc: u32, // 0..8
134
    pub lp: u32, // 0..4
135
    // context for literal/match is plaintext offset modulo 2^pb
136
    pub pb: u32, // 0..4
137
    unpacked_size: Option<u64>,
138
    literal_probs: Vec<Vec<u16>>,
139
    pos_slot_decoder: Vec<rangecoder::BitTree>,
140
    align_decoder: rangecoder::BitTree,
141
    pos_decoders: [u16; 115],
142
    is_match: [u16; 192], // true = LZ, false = literal
143
    is_rep: [u16; 12],
144
    is_rep_g0: [u16; 12],
145
    is_rep_g1: [u16; 12],
146
    is_rep_g2: [u16; 12],
147
    is_rep_0long: [u16; 192],
148
    state: usize,
149
    rep: [usize; 4],
150
    len_decoder: rangecoder::LenDecoder,
151
    rep_len_decoder: rangecoder::LenDecoder,
152
}
153
154
// Initialize decoder with accumulating buffer
155
0
pub fn new_accum<W>(
156
0
    output: lzbuffer::LzAccumBuffer<W>,
157
0
    lc: u32,
158
0
    lp: u32,
159
0
    pb: u32,
160
0
    unpacked_size: Option<u64>,
161
0
) -> DecoderState<W, lzbuffer::LzAccumBuffer<W>>
162
0
where
163
0
    W: io::Write,
164
{
165
0
    DecoderState {
166
0
        _phantom: PhantomData,
167
0
        partial_input_buf: std::io::Cursor::new([0; MAX_REQUIRED_INPUT]),
168
0
        output,
169
0
        lc,
170
0
        lp,
171
0
        pb,
172
0
        unpacked_size,
173
0
        literal_probs: vec![vec![0x400; 0x300]; 1 << (lc + lp)],
174
0
        pos_slot_decoder: vec![rangecoder::BitTree::new(6); 4],
175
0
        align_decoder: rangecoder::BitTree::new(4),
176
0
        pos_decoders: [0x400; 115],
177
0
        is_match: [0x400; 192],
178
0
        is_rep: [0x400; 12],
179
0
        is_rep_g0: [0x400; 12],
180
0
        is_rep_g1: [0x400; 12],
181
0
        is_rep_g2: [0x400; 12],
182
0
        is_rep_0long: [0x400; 192],
183
0
        state: 0,
184
0
        rep: [0; 4],
185
0
        len_decoder: rangecoder::LenDecoder::new(),
186
0
        rep_len_decoder: rangecoder::LenDecoder::new(),
187
0
    }
188
0
}
189
190
// Initialize decoder with circular buffer
191
0
pub fn new_circular<W>(
192
0
    output: W,
193
0
    params: LzmaParams,
194
0
) -> error::Result<DecoderState<W, lzbuffer::LzCircularBuffer<W>>>
195
0
where
196
0
    W: io::Write,
197
{
198
0
    new_circular_with_memlimit(output, params, std::usize::MAX)
199
0
}
Unexecuted instantiation: lzma_rs::decode::lzma::new_circular::<suricata::lzma::LzmaOutput>
Unexecuted instantiation: lzma_rs::decode::lzma::new_circular::<suricata_htp::decompressors::BlockingCursor>
Unexecuted instantiation: lzma_rs::decode::lzma::new_circular::<_>
Unexecuted instantiation: lzma_rs::decode::lzma::new_circular::<suricata::lzma::LzmaOutput>
Unexecuted instantiation: lzma_rs::decode::lzma::new_circular::<suricata_htp::decompressors::BlockingCursor>
200
201
// Initialize decoder with circular buffer
202
55.8k
pub fn new_circular_with_memlimit<W>(
203
55.8k
    output: W,
204
55.8k
    params: LzmaParams,
205
55.8k
    memlimit: usize,
206
55.8k
) -> error::Result<DecoderState<W, lzbuffer::LzCircularBuffer<W>>>
207
55.8k
where
208
55.8k
    W: io::Write,
209
{
210
    // Decoder
211
55.8k
    let decoder = DecoderState {
212
55.8k
        _phantom: PhantomData,
213
55.8k
        output: lzbuffer::LzCircularBuffer::from_stream_with_memlimit(
214
55.8k
            output,
215
55.8k
            params.dict_size as usize,
216
55.8k
            memlimit,
217
55.8k
        ),
218
55.8k
        partial_input_buf: std::io::Cursor::new([0; MAX_REQUIRED_INPUT]),
219
55.8k
        lc: params.lc,
220
55.8k
        lp: params.lp,
221
55.8k
        pb: params.pb,
222
55.8k
        unpacked_size: params.unpacked_size,
223
55.8k
        literal_probs: vec![vec![0x400; 0x300]; 1 << (params.lc + params.lp)],
224
55.8k
        pos_slot_decoder: vec![rangecoder::BitTree::new(6); 4],
225
55.8k
        align_decoder: rangecoder::BitTree::new(4),
226
55.8k
        pos_decoders: [0x400; 115],
227
55.8k
        is_match: [0x400; 192],
228
55.8k
        is_rep: [0x400; 12],
229
55.8k
        is_rep_g0: [0x400; 12],
230
55.8k
        is_rep_g1: [0x400; 12],
231
55.8k
        is_rep_g2: [0x400; 12],
232
55.8k
        is_rep_0long: [0x400; 192],
233
55.8k
        state: 0,
234
55.8k
        rep: [0; 4],
235
55.8k
        len_decoder: rangecoder::LenDecoder::new(),
236
55.8k
        rep_len_decoder: rangecoder::LenDecoder::new(),
237
55.8k
    };
238
239
55.8k
    Ok(decoder)
240
55.8k
}
Unexecuted instantiation: lzma_rs::decode::lzma::new_circular_with_memlimit::<suricata::lzma::LzmaOutput>
Unexecuted instantiation: lzma_rs::decode::lzma::new_circular_with_memlimit::<_>
lzma_rs::decode::lzma::new_circular_with_memlimit::<suricata_htp::decompressors::BlockingCursor>
Line
Count
Source
202
4.84k
pub fn new_circular_with_memlimit<W>(
203
4.84k
    output: W,
204
4.84k
    params: LzmaParams,
205
4.84k
    memlimit: usize,
206
4.84k
) -> error::Result<DecoderState<W, lzbuffer::LzCircularBuffer<W>>>
207
4.84k
where
208
4.84k
    W: io::Write,
209
{
210
    // Decoder
211
4.84k
    let decoder = DecoderState {
212
4.84k
        _phantom: PhantomData,
213
4.84k
        output: lzbuffer::LzCircularBuffer::from_stream_with_memlimit(
214
4.84k
            output,
215
4.84k
            params.dict_size as usize,
216
4.84k
            memlimit,
217
4.84k
        ),
218
4.84k
        partial_input_buf: std::io::Cursor::new([0; MAX_REQUIRED_INPUT]),
219
4.84k
        lc: params.lc,
220
4.84k
        lp: params.lp,
221
4.84k
        pb: params.pb,
222
4.84k
        unpacked_size: params.unpacked_size,
223
4.84k
        literal_probs: vec![vec![0x400; 0x300]; 1 << (params.lc + params.lp)],
224
4.84k
        pos_slot_decoder: vec![rangecoder::BitTree::new(6); 4],
225
4.84k
        align_decoder: rangecoder::BitTree::new(4),
226
4.84k
        pos_decoders: [0x400; 115],
227
4.84k
        is_match: [0x400; 192],
228
4.84k
        is_rep: [0x400; 12],
229
4.84k
        is_rep_g0: [0x400; 12],
230
4.84k
        is_rep_g1: [0x400; 12],
231
4.84k
        is_rep_g2: [0x400; 12],
232
4.84k
        is_rep_0long: [0x400; 192],
233
4.84k
        state: 0,
234
4.84k
        rep: [0; 4],
235
4.84k
        len_decoder: rangecoder::LenDecoder::new(),
236
4.84k
        rep_len_decoder: rangecoder::LenDecoder::new(),
237
4.84k
    };
238
239
4.84k
    Ok(decoder)
240
4.84k
}
Unexecuted instantiation: lzma_rs::decode::lzma::new_circular_with_memlimit::<suricata::lzma::LzmaOutput>
lzma_rs::decode::lzma::new_circular_with_memlimit::<suricata_htp::decompressors::BlockingCursor>
Line
Count
Source
202
51.0k
pub fn new_circular_with_memlimit<W>(
203
51.0k
    output: W,
204
51.0k
    params: LzmaParams,
205
51.0k
    memlimit: usize,
206
51.0k
) -> error::Result<DecoderState<W, lzbuffer::LzCircularBuffer<W>>>
207
51.0k
where
208
51.0k
    W: io::Write,
209
{
210
    // Decoder
211
51.0k
    let decoder = DecoderState {
212
51.0k
        _phantom: PhantomData,
213
51.0k
        output: lzbuffer::LzCircularBuffer::from_stream_with_memlimit(
214
51.0k
            output,
215
51.0k
            params.dict_size as usize,
216
51.0k
            memlimit,
217
51.0k
        ),
218
51.0k
        partial_input_buf: std::io::Cursor::new([0; MAX_REQUIRED_INPUT]),
219
51.0k
        lc: params.lc,
220
51.0k
        lp: params.lp,
221
51.0k
        pb: params.pb,
222
51.0k
        unpacked_size: params.unpacked_size,
223
51.0k
        literal_probs: vec![vec![0x400; 0x300]; 1 << (params.lc + params.lp)],
224
51.0k
        pos_slot_decoder: vec![rangecoder::BitTree::new(6); 4],
225
51.0k
        align_decoder: rangecoder::BitTree::new(4),
226
51.0k
        pos_decoders: [0x400; 115],
227
51.0k
        is_match: [0x400; 192],
228
51.0k
        is_rep: [0x400; 12],
229
51.0k
        is_rep_g0: [0x400; 12],
230
51.0k
        is_rep_g1: [0x400; 12],
231
51.0k
        is_rep_g2: [0x400; 12],
232
51.0k
        is_rep_0long: [0x400; 192],
233
51.0k
        state: 0,
234
51.0k
        rep: [0; 4],
235
51.0k
        len_decoder: rangecoder::LenDecoder::new(),
236
51.0k
        rep_len_decoder: rangecoder::LenDecoder::new(),
237
51.0k
    };
238
239
51.0k
    Ok(decoder)
240
51.0k
}
241
242
impl<W, LZB> DecoderState<W, LZB>
243
where
244
    W: io::Write,
245
    LZB: lzbuffer::LzBuffer<W>,
246
{
247
0
    pub fn reset_state(&mut self, lc: u32, lp: u32, pb: u32) {
248
0
        self.lc = lc;
249
0
        self.lp = lp;
250
0
        self.pb = pb;
251
0
        self.literal_probs = vec![vec![0x400; 0x300]; 1 << (lc + lp)];
252
0
        self.pos_slot_decoder = vec![rangecoder::BitTree::new(6); 4];
253
0
        self.align_decoder = rangecoder::BitTree::new(4);
254
0
        self.pos_decoders = [0x400; 115];
255
0
        self.is_match = [0x400; 192];
256
0
        self.is_rep = [0x400; 12];
257
0
        self.is_rep_g0 = [0x400; 12];
258
0
        self.is_rep_g1 = [0x400; 12];
259
0
        self.is_rep_g2 = [0x400; 12];
260
0
        self.is_rep_0long = [0x400; 192];
261
0
        self.state = 0;
262
0
        self.rep = [0; 4];
263
0
        self.len_decoder = rangecoder::LenDecoder::new();
264
0
        self.rep_len_decoder = rangecoder::LenDecoder::new();
265
0
    }
266
267
0
    pub fn set_unpacked_size(&mut self, unpacked_size: Option<u64>) {
268
0
        self.unpacked_size = unpacked_size;
269
0
    }
270
271
4.15k
    pub fn process<'a, R: io::BufRead>(
272
4.15k
        &mut self,
273
4.15k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
274
4.15k
    ) -> error::Result<()> {
275
4.15k
        self.process_mode(rangecoder, ProcessingMode::Finish)
276
4.15k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process::<std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
271
18
    pub fn process<'a, R: io::BufRead>(
272
18
        &mut self,
273
18
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
274
18
    ) -> error::Result<()> {
275
18
        self.process_mode(rangecoder, ProcessingMode::Finish)
276
18
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<_, _>>::process::<_>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process::<std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
271
4.14k
    pub fn process<'a, R: io::BufRead>(
272
4.14k
        &mut self,
273
4.14k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
274
4.14k
    ) -> error::Result<()> {
275
4.14k
        self.process_mode(rangecoder, ProcessingMode::Finish)
276
4.14k
    }
277
278
    #[cfg(feature = "stream")]
279
94.3k
    pub fn process_stream<'a, R: io::BufRead>(
280
94.3k
        &mut self,
281
94.3k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
282
94.3k
    ) -> error::Result<()> {
283
94.3k
        self.process_mode(rangecoder, ProcessingMode::Partial)
284
94.3k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_stream::<&mut std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_stream::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
279
6.55k
    pub fn process_stream<'a, R: io::BufRead>(
280
6.55k
        &mut self,
281
6.55k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
282
6.55k
    ) -> error::Result<()> {
283
6.55k
        self.process_mode(rangecoder, ProcessingMode::Partial)
284
6.55k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<_, _>>::process_stream::<_>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_stream::<&mut std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_stream::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
279
87.7k
    pub fn process_stream<'a, R: io::BufRead>(
280
87.7k
        &mut self,
281
87.7k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
282
87.7k
    ) -> error::Result<()> {
283
87.7k
        self.process_mode(rangecoder, ProcessingMode::Partial)
284
87.7k
    }
285
286
    /// Process the next iteration of the loop.
287
    ///
288
    /// If the update flag is true, the decoder's state will be updated.
289
    ///
290
    /// Returns `ProcessingStatus` to determine whether one should continue
291
    /// processing the loop.
292
4.00M
    fn process_next_inner<'a, R: io::BufRead>(
293
4.00M
        &mut self,
294
4.00M
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
295
4.00M
        update: bool,
296
4.00M
    ) -> error::Result<ProcessingStatus> {
297
4.00M
        let pos_state = self.output.len() & ((1 << self.pb) - 1);
298
299
        // Literal
300
4.00M
        if !rangecoder.decode_bit(
301
            // TODO: assumes pb = 2 ??
302
4.00M
            &mut self.is_match[(self.state << 4) + pos_state],
303
4.00M
            update,
304
2.38k
        )? {
305
3.22M
            let byte: u8 = self.decode_literal(rangecoder, update)?;
306
307
3.21M
            if update {
308
                lzma_debug!("Literal: {}", byte);
309
3.07M
                self.output.append_literal(byte)?;
310
311
3.07M
                self.state = if self.state < 4 {
312
2.99M
                    0
313
74.4k
                } else if self.state < 10 {
314
56.0k
                    self.state - 3
315
                } else {
316
18.3k
                    self.state - 6
317
                };
318
136k
            }
319
3.21M
            return Ok(ProcessingStatus::Continue);
320
776k
        }
321
322
        // LZ
323
        let mut len: usize;
324
        // Distance is repeated from LRU
325
776k
        if rangecoder.decode_bit(&mut self.is_rep[self.state], update)? {
326
            // dist = rep[0]
327
687k
            if !rangecoder.decode_bit(&mut self.is_rep_g0[self.state], update)? {
328
                // len = 1
329
65.6k
                if !rangecoder.decode_bit(
330
65.6k
                    &mut self.is_rep_0long[(self.state << 4) + pos_state],
331
65.6k
                    update,
332
519
                )? {
333
                    // update state (short rep)
334
26.1k
                    if update {
335
16.0k
                        self.state = if self.state < 7 { 9 } else { 11 };
336
16.0k
                        let dist = self.rep[0] + 1;
337
16.0k
                        self.output.append_lz(1, dist)?;
338
10.1k
                    }
339
25.0k
                    return Ok(ProcessingStatus::Continue);
340
38.9k
                }
341
            // dist = rep[i]
342
            } else {
343
                let idx: usize;
344
618k
                if !rangecoder.decode_bit(&mut self.is_rep_g1[self.state], update)? {
345
42.3k
                    idx = 1;
346
574k
                } else if !rangecoder.decode_bit(&mut self.is_rep_g2[self.state], update)? {
347
25.0k
                    idx = 2;
348
548k
                } else {
349
548k
                    idx = 3;
350
548k
                }
351
615k
                if update {
352
                    // Update LRU
353
443k
                    let dist = self.rep[idx];
354
1.26M
                    for i in (0..idx).rev() {
355
1.26M
                        self.rep[i + 1] = self.rep[i];
356
1.26M
                    }
357
443k
                    self.rep[0] = dist
358
171k
                }
359
            }
360
361
654k
            len = self.rep_len_decoder.decode(rangecoder, pos_state, update)?;
362
363
639k
            if update {
364
                // update state (rep)
365
463k
                self.state = if self.state < 7 { 8 } else { 11 };
366
175k
            }
367
        // New distance
368
        } else {
369
87.5k
            if update {
370
43.8k
                // Update LRU
371
43.8k
                self.rep[3] = self.rep[2];
372
43.8k
                self.rep[2] = self.rep[1];
373
43.8k
                self.rep[1] = self.rep[0];
374
43.8k
            }
375
376
87.5k
            len = self.len_decoder.decode(rangecoder, pos_state, update)?;
377
378
84.5k
            if update {
379
                // update state (match)
380
43.6k
                self.state = if self.state < 7 { 7 } else { 10 };
381
40.8k
            }
382
383
84.5k
            let rep_0 = self.decode_distance(rangecoder, len, update)?;
384
385
69.7k
            if update {
386
43.5k
                self.rep[0] = rep_0;
387
43.5k
                if self.rep[0] == 0xFFFF_FFFF {
388
951
                    if rangecoder.is_finished_ok()? {
389
3
                        return Ok(ProcessingStatus::Finished);
390
948
                    }
391
948
                    return Err(error::Error::LzmaError(String::from(
392
948
                        "Found end-of-stream marker but more bytes are available",
393
948
                    )));
394
42.6k
                }
395
26.2k
            }
396
        }
397
398
708k
        if update {
399
506k
            len += 2;
400
401
506k
            let dist = self.rep[0] + 1;
402
506k
            self.output.append_lz(len, dist)?;
403
202k
        }
404
405
681k
        Ok(ProcessingStatus::Continue)
406
4.00M
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_next_inner::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_next_inner::<&mut std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<_, _>>::process_next_inner::<_>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_next_inner::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
292
28.5k
    fn process_next_inner<'a, R: io::BufRead>(
293
28.5k
        &mut self,
294
28.5k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
295
28.5k
        update: bool,
296
28.5k
    ) -> error::Result<ProcessingStatus> {
297
28.5k
        let pos_state = self.output.len() & ((1 << self.pb) - 1);
298
299
        // Literal
300
28.5k
        if !rangecoder.decode_bit(
301
            // TODO: assumes pb = 2 ??
302
28.5k
            &mut self.is_match[(self.state << 4) + pos_state],
303
28.5k
            update,
304
15
        )? {
305
17.5k
            let byte: u8 = self.decode_literal(rangecoder, update)?;
306
307
16.2k
            if update {
308
                lzma_debug!("Literal: {}", byte);
309
1.65k
                self.output.append_literal(byte)?;
310
311
1.65k
                self.state = if self.state < 4 {
312
689
                    0
313
968
                } else if self.state < 10 {
314
617
                    self.state - 3
315
                } else {
316
351
                    self.state - 6
317
                };
318
14.5k
            }
319
16.2k
            return Ok(ProcessingStatus::Continue);
320
11.0k
        }
321
322
        // LZ
323
        let mut len: usize;
324
        // Distance is repeated from LRU
325
11.0k
        if rangecoder.decode_bit(&mut self.is_rep[self.state], update)? {
326
            // dist = rep[0]
327
7.42k
            if !rangecoder.decode_bit(&mut self.is_rep_g0[self.state], update)? {
328
                // len = 1
329
3.44k
                if !rangecoder.decode_bit(
330
3.44k
                    &mut self.is_rep_0long[(self.state << 4) + pos_state],
331
3.44k
                    update,
332
4
                )? {
333
                    // update state (short rep)
334
1.75k
                    if update {
335
376
                        self.state = if self.state < 7 { 9 } else { 11 };
336
376
                        let dist = self.rep[0] + 1;
337
376
                        self.output.append_lz(1, dist)?;
338
1.38k
                    }
339
1.75k
                    return Ok(ProcessingStatus::Continue);
340
1.67k
                }
341
            // dist = rep[i]
342
            } else {
343
                let idx: usize;
344
3.98k
                if !rangecoder.decode_bit(&mut self.is_rep_g1[self.state], update)? {
345
1.17k
                    idx = 1;
346
2.79k
                } else if !rangecoder.decode_bit(&mut self.is_rep_g2[self.state], update)? {
347
166
                    idx = 2;
348
2.62k
                } else {
349
2.62k
                    idx = 3;
350
2.62k
                }
351
3.96k
                if update {
352
                    // Update LRU
353
370
                    let dist = self.rep[idx];
354
1.04k
                    for i in (0..idx).rev() {
355
1.04k
                        self.rep[i + 1] = self.rep[i];
356
1.04k
                    }
357
370
                    self.rep[0] = dist
358
3.59k
                }
359
            }
360
361
5.64k
            len = self.rep_len_decoder.decode(rangecoder, pos_state, update)?;
362
363
5.31k
            if update {
364
                // update state (rep)
365
1.01k
                self.state = if self.state < 7 { 8 } else { 11 };
366
4.29k
            }
367
        // New distance
368
        } else {
369
3.57k
            if update {
370
1.30k
                // Update LRU
371
1.30k
                self.rep[3] = self.rep[2];
372
1.30k
                self.rep[2] = self.rep[1];
373
1.30k
                self.rep[1] = self.rep[0];
374
2.26k
            }
375
376
3.57k
            len = self.len_decoder.decode(rangecoder, pos_state, update)?;
377
378
3.51k
            if update {
379
                // update state (match)
380
1.30k
                self.state = if self.state < 7 { 7 } else { 10 };
381
2.21k
            }
382
383
3.51k
            let rep_0 = self.decode_distance(rangecoder, len, update)?;
384
385
2.22k
            if update {
386
1.29k
                self.rep[0] = rep_0;
387
1.29k
                if self.rep[0] == 0xFFFF_FFFF {
388
0
                    if rangecoder.is_finished_ok()? {
389
0
                        return Ok(ProcessingStatus::Finished);
390
0
                    }
391
0
                    return Err(error::Error::LzmaError(String::from(
392
0
                        "Found end-of-stream marker but more bytes are available",
393
0
                    )));
394
1.29k
                }
395
932
            }
396
        }
397
398
7.54k
        if update {
399
2.31k
            len += 2;
400
401
2.31k
            let dist = self.rep[0] + 1;
402
2.31k
            self.output.append_lz(len, dist)?;
403
5.23k
        }
404
405
6.25k
        Ok(ProcessingStatus::Continue)
406
28.5k
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_next_inner::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
292
98.7k
    fn process_next_inner<'a, R: io::BufRead>(
293
98.7k
        &mut self,
294
98.7k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
295
98.7k
        update: bool,
296
98.7k
    ) -> error::Result<ProcessingStatus> {
297
98.7k
        let pos_state = self.output.len() & ((1 << self.pb) - 1);
298
299
        // Literal
300
98.7k
        if !rangecoder.decode_bit(
301
            // TODO: assumes pb = 2 ??
302
98.7k
            &mut self.is_match[(self.state << 4) + pos_state],
303
98.7k
            update,
304
0
        )? {
305
61.4k
            let byte: u8 = self.decode_literal(rangecoder, update)?;
306
307
61.4k
            if update {
308
                lzma_debug!("Literal: {}", byte);
309
61.4k
                self.output.append_literal(byte)?;
310
311
61.4k
                self.state = if self.state < 4 {
312
58.3k
                    0
313
3.11k
                } else if self.state < 10 {
314
2.69k
                    self.state - 3
315
                } else {
316
421
                    self.state - 6
317
                };
318
0
            }
319
61.4k
            return Ok(ProcessingStatus::Continue);
320
37.3k
        }
321
322
        // LZ
323
        let mut len: usize;
324
        // Distance is repeated from LRU
325
37.3k
        if rangecoder.decode_bit(&mut self.is_rep[self.state], update)? {
326
            // dist = rep[0]
327
34.5k
            if !rangecoder.decode_bit(&mut self.is_rep_g0[self.state], update)? {
328
                // len = 1
329
2.17k
                if !rangecoder.decode_bit(
330
2.17k
                    &mut self.is_rep_0long[(self.state << 4) + pos_state],
331
2.17k
                    update,
332
0
                )? {
333
                    // update state (short rep)
334
1.39k
                    if update {
335
1.39k
                        self.state = if self.state < 7 { 9 } else { 11 };
336
1.39k
                        let dist = self.rep[0] + 1;
337
1.39k
                        self.output.append_lz(1, dist)?;
338
0
                    }
339
1.38k
                    return Ok(ProcessingStatus::Continue);
340
777
                }
341
            // dist = rep[i]
342
            } else {
343
                let idx: usize;
344
32.3k
                if !rangecoder.decode_bit(&mut self.is_rep_g1[self.state], update)? {
345
1.52k
                    idx = 1;
346
30.8k
                } else if !rangecoder.decode_bit(&mut self.is_rep_g2[self.state], update)? {
347
315
                    idx = 2;
348
30.4k
                } else {
349
30.4k
                    idx = 3;
350
30.4k
                }
351
32.3k
                if update {
352
                    // Update LRU
353
32.3k
                    let dist = self.rep[idx];
354
93.6k
                    for i in (0..idx).rev() {
355
93.6k
                        self.rep[i + 1] = self.rep[i];
356
93.6k
                    }
357
32.3k
                    self.rep[0] = dist
358
0
                }
359
            }
360
361
33.1k
            len = self.rep_len_decoder.decode(rangecoder, pos_state, update)?;
362
363
33.1k
            if update {
364
                // update state (rep)
365
33.1k
                self.state = if self.state < 7 { 8 } else { 11 };
366
0
            }
367
        // New distance
368
        } else {
369
2.79k
            if update {
370
2.79k
                // Update LRU
371
2.79k
                self.rep[3] = self.rep[2];
372
2.79k
                self.rep[2] = self.rep[1];
373
2.79k
                self.rep[1] = self.rep[0];
374
2.79k
            }
375
376
2.79k
            len = self.len_decoder.decode(rangecoder, pos_state, update)?;
377
378
2.79k
            if update {
379
                // update state (match)
380
2.79k
                self.state = if self.state < 7 { 7 } else { 10 };
381
0
            }
382
383
2.79k
            let rep_0 = self.decode_distance(rangecoder, len, update)?;
384
385
2.79k
            if update {
386
2.79k
                self.rep[0] = rep_0;
387
2.79k
                if self.rep[0] == 0xFFFF_FFFF {
388
1
                    if rangecoder.is_finished_ok()? {
389
0
                        return Ok(ProcessingStatus::Finished);
390
1
                    }
391
1
                    return Err(error::Error::LzmaError(String::from(
392
1
                        "Found end-of-stream marker but more bytes are available",
393
1
                    )));
394
2.79k
                }
395
0
            }
396
        }
397
398
35.9k
        if update {
399
35.9k
            len += 2;
400
401
35.9k
            let dist = self.rep[0] + 1;
402
35.9k
            self.output.append_lz(len, dist)?;
403
0
        }
404
405
33.7k
        Ok(ProcessingStatus::Continue)
406
98.7k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_next_inner::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_next_inner::<&mut std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_next_inner::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
292
461k
    fn process_next_inner<'a, R: io::BufRead>(
293
461k
        &mut self,
294
461k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
295
461k
        update: bool,
296
461k
    ) -> error::Result<ProcessingStatus> {
297
461k
        let pos_state = self.output.len() & ((1 << self.pb) - 1);
298
299
        // Literal
300
461k
        if !rangecoder.decode_bit(
301
            // TODO: assumes pb = 2 ??
302
461k
            &mut self.is_match[(self.state << 4) + pos_state],
303
461k
            update,
304
2.37k
        )? {
305
166k
            let byte: u8 = self.decode_literal(rangecoder, update)?;
306
307
152k
            if update {
308
                lzma_debug!("Literal: {}", byte);
309
30.5k
                self.output.append_literal(byte)?;
310
311
30.5k
                self.state = if self.state < 4 {
312
4.72k
                    0
313
25.8k
                } else if self.state < 10 {
314
16.2k
                    self.state - 3
315
                } else {
316
9.57k
                    self.state - 6
317
                };
318
121k
            }
319
152k
            return Ok(ProcessingStatus::Continue);
320
292k
        }
321
322
        // LZ
323
        let mut len: usize;
324
        // Distance is repeated from LRU
325
292k
        if rangecoder.decode_bit(&mut self.is_rep[self.state], update)? {
326
            // dist = rep[0]
327
234k
            if !rangecoder.decode_bit(&mut self.is_rep_g0[self.state], update)? {
328
                // len = 1
329
33.5k
                if !rangecoder.decode_bit(
330
33.5k
                    &mut self.is_rep_0long[(self.state << 4) + pos_state],
331
33.5k
                    update,
332
515
                )? {
333
                    // update state (short rep)
334
12.0k
                    if update {
335
3.28k
                        self.state = if self.state < 7 { 9 } else { 11 };
336
3.28k
                        let dist = self.rep[0] + 1;
337
3.28k
                        self.output.append_lz(1, dist)?;
338
8.76k
                    }
339
11.8k
                    return Ok(ProcessingStatus::Continue);
340
20.9k
                }
341
            // dist = rep[i]
342
            } else {
343
                let idx: usize;
344
197k
                if !rangecoder.decode_bit(&mut self.is_rep_g1[self.state], update)? {
345
25.0k
                    idx = 1;
346
170k
                } else if !rangecoder.decode_bit(&mut self.is_rep_g2[self.state], update)? {
347
15.0k
                    idx = 2;
348
154k
                } else {
349
154k
                    idx = 3;
350
154k
                }
351
194k
                if update {
352
                    // Update LRU
353
26.1k
                    let dist = self.rep[idx];
354
54.4k
                    for i in (0..idx).rev() {
355
54.4k
                        self.rep[i + 1] = self.rep[i];
356
54.4k
                    }
357
26.1k
                    self.rep[0] = dist
358
168k
                }
359
            }
360
361
215k
            len = self.rep_len_decoder.decode(rangecoder, pos_state, update)?;
362
363
201k
            if update {
364
                // update state (rep)
365
29.5k
                self.state = if self.state < 7 { 8 } else { 11 };
366
171k
            }
367
        // New distance
368
        } else {
369
56.9k
            if update {
370
15.5k
                // Update LRU
371
15.5k
                self.rep[3] = self.rep[2];
372
15.5k
                self.rep[2] = self.rep[1];
373
15.5k
                self.rep[1] = self.rep[0];
374
41.4k
            }
375
376
56.9k
            len = self.len_decoder.decode(rangecoder, pos_state, update)?;
377
378
53.9k
            if update {
379
                // update state (match)
380
15.3k
                self.state = if self.state < 7 { 7 } else { 10 };
381
38.6k
            }
382
383
53.9k
            let rep_0 = self.decode_distance(rangecoder, len, update)?;
384
385
40.5k
            if update {
386
15.2k
                self.rep[0] = rep_0;
387
15.2k
                if self.rep[0] == 0xFFFF_FFFF {
388
378
                    if rangecoder.is_finished_ok()? {
389
0
                        return Ok(ProcessingStatus::Finished);
390
378
                    }
391
378
                    return Err(error::Error::LzmaError(String::from(
392
378
                        "Found end-of-stream marker but more bytes are available",
393
378
                    )));
394
14.8k
                }
395
25.2k
            }
396
        }
397
398
241k
        if update {
399
44.4k
            len += 2;
400
401
44.4k
            let dist = self.rep[0] + 1;
402
44.4k
            self.output.append_lz(len, dist)?;
403
196k
        }
404
405
234k
        Ok(ProcessingStatus::Continue)
406
461k
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_next_inner::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
292
3.41M
    fn process_next_inner<'a, R: io::BufRead>(
293
3.41M
        &mut self,
294
3.41M
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
295
3.41M
        update: bool,
296
3.41M
    ) -> error::Result<ProcessingStatus> {
297
3.41M
        let pos_state = self.output.len() & ((1 << self.pb) - 1);
298
299
        // Literal
300
3.41M
        if !rangecoder.decode_bit(
301
            // TODO: assumes pb = 2 ??
302
3.41M
            &mut self.is_match[(self.state << 4) + pos_state],
303
3.41M
            update,
304
0
        )? {
305
2.98M
            let byte: u8 = self.decode_literal(rangecoder, update)?;
306
307
2.98M
            if update {
308
                lzma_debug!("Literal: {}", byte);
309
2.98M
                self.output.append_literal(byte)?;
310
311
2.98M
                self.state = if self.state < 4 {
312
2.93M
                    0
313
44.5k
                } else if self.state < 10 {
314
36.5k
                    self.state - 3
315
                } else {
316
8.04k
                    self.state - 6
317
                };
318
0
            }
319
2.98M
            return Ok(ProcessingStatus::Continue);
320
435k
        }
321
322
        // LZ
323
        let mut len: usize;
324
        // Distance is repeated from LRU
325
435k
        if rangecoder.decode_bit(&mut self.is_rep[self.state], update)? {
326
            // dist = rep[0]
327
411k
            if !rangecoder.decode_bit(&mut self.is_rep_g0[self.state], update)? {
328
                // len = 1
329
26.5k
                if !rangecoder.decode_bit(
330
26.5k
                    &mut self.is_rep_0long[(self.state << 4) + pos_state],
331
26.5k
                    update,
332
0
                )? {
333
                    // update state (short rep)
334
10.9k
                    if update {
335
10.9k
                        self.state = if self.state < 7 { 9 } else { 11 };
336
10.9k
                        let dist = self.rep[0] + 1;
337
10.9k
                        self.output.append_lz(1, dist)?;
338
0
                    }
339
10.0k
                    return Ok(ProcessingStatus::Continue);
340
15.5k
                }
341
            // dist = rep[i]
342
            } else {
343
                let idx: usize;
344
384k
                if !rangecoder.decode_bit(&mut self.is_rep_g1[self.state], update)? {
345
14.5k
                    idx = 1;
346
370k
                } else if !rangecoder.decode_bit(&mut self.is_rep_g2[self.state], update)? {
347
9.45k
                    idx = 2;
348
360k
                } else {
349
360k
                    idx = 3;
350
360k
                }
351
384k
                if update {
352
                    // Update LRU
353
384k
                    let dist = self.rep[idx];
354
1.11M
                    for i in (0..idx).rev() {
355
1.11M
                        self.rep[i + 1] = self.rep[i];
356
1.11M
                    }
357
384k
                    self.rep[0] = dist
358
0
                }
359
            }
360
361
400k
            len = self.rep_len_decoder.decode(rangecoder, pos_state, update)?;
362
363
400k
            if update {
364
                // update state (rep)
365
400k
                self.state = if self.state < 7 { 8 } else { 11 };
366
0
            }
367
        // New distance
368
        } else {
369
24.2k
            if update {
370
24.2k
                // Update LRU
371
24.2k
                self.rep[3] = self.rep[2];
372
24.2k
                self.rep[2] = self.rep[1];
373
24.2k
                self.rep[1] = self.rep[0];
374
24.2k
            }
375
376
24.2k
            len = self.len_decoder.decode(rangecoder, pos_state, update)?;
377
378
24.2k
            if update {
379
                // update state (match)
380
24.2k
                self.state = if self.state < 7 { 7 } else { 10 };
381
0
            }
382
383
24.2k
            let rep_0 = self.decode_distance(rangecoder, len, update)?;
384
385
24.2k
            if update {
386
24.2k
                self.rep[0] = rep_0;
387
24.2k
                if self.rep[0] == 0xFFFF_FFFF {
388
572
                    if rangecoder.is_finished_ok()? {
389
3
                        return Ok(ProcessingStatus::Finished);
390
569
                    }
391
569
                    return Err(error::Error::LzmaError(String::from(
392
569
                        "Found end-of-stream marker but more bytes are available",
393
569
                    )));
394
23.6k
                }
395
0
            }
396
        }
397
398
423k
        if update {
399
423k
            len += 2;
400
401
423k
            let dist = self.rep[0] + 1;
402
423k
            self.output.append_lz(len, dist)?;
403
0
        }
404
405
406k
        Ok(ProcessingStatus::Continue)
406
3.41M
    }
407
408
3.59M
    fn process_next<'a, R: io::BufRead>(
409
3.59M
        &mut self,
410
3.59M
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
411
3.59M
    ) -> error::Result<ProcessingStatus> {
412
3.59M
        self.process_next_inner(rangecoder, true)
413
3.59M
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_next::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_next::<&mut std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<_, _>>::process_next::<_>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_next::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
408
4.35k
    fn process_next<'a, R: io::BufRead>(
409
4.35k
        &mut self,
410
4.35k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
411
4.35k
    ) -> error::Result<ProcessingStatus> {
412
4.35k
        self.process_next_inner(rangecoder, true)
413
4.35k
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_next::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
408
98.7k
    fn process_next<'a, R: io::BufRead>(
409
98.7k
        &mut self,
410
98.7k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
411
98.7k
    ) -> error::Result<ProcessingStatus> {
412
98.7k
        self.process_next_inner(rangecoder, true)
413
98.7k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_next::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_next::<&mut std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_next::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
408
80.6k
    fn process_next<'a, R: io::BufRead>(
409
80.6k
        &mut self,
410
80.6k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
411
80.6k
    ) -> error::Result<ProcessingStatus> {
412
80.6k
        self.process_next_inner(rangecoder, true)
413
80.6k
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_next::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
408
3.41M
    fn process_next<'a, R: io::BufRead>(
409
3.41M
        &mut self,
410
3.41M
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
411
3.41M
    ) -> error::Result<ProcessingStatus> {
412
3.41M
        self.process_next_inner(rangecoder, true)
413
3.41M
    }
414
415
    /// Try to process the next iteration of the loop.
416
    ///
417
    /// This will check to see if there is enough data to consume and advance the
418
    /// decompressor. Needed in streaming mode to avoid corrupting the state while
419
    /// processing incomplete chunks of data.
420
404k
    fn try_process_next(&mut self, buf: &[u8], range: u32, code: u32) -> error::Result<()> {
421
404k
        let mut temp = std::io::Cursor::new(buf);
422
404k
        let mut rangecoder = rangecoder::RangeDecoder::from_parts(&mut temp, range, code);
423
404k
        let _ = self.process_next_inner(&mut rangecoder, false)?;
424
348k
        Ok(())
425
404k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::try_process_next
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<_, _>>::try_process_next
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::try_process_next
Line
Count
Source
420
24.2k
    fn try_process_next(&mut self, buf: &[u8], range: u32, code: u32) -> error::Result<()> {
421
24.2k
        let mut temp = std::io::Cursor::new(buf);
422
24.2k
        let mut rangecoder = rangecoder::RangeDecoder::from_parts(&mut temp, range, code);
423
24.2k
        let _ = self.process_next_inner(&mut rangecoder, false)?;
424
21.1k
        Ok(())
425
24.2k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::try_process_next
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::try_process_next
Line
Count
Source
420
380k
    fn try_process_next(&mut self, buf: &[u8], range: u32, code: u32) -> error::Result<()> {
421
380k
        let mut temp = std::io::Cursor::new(buf);
422
380k
        let mut rangecoder = rangecoder::RangeDecoder::from_parts(&mut temp, range, code);
423
380k
        let _ = self.process_next_inner(&mut rangecoder, false)?;
424
327k
        Ok(())
425
380k
    }
426
427
    /// Utility function to read data into the partial input buffer.
428
139k
    fn read_partial_input_buf<'a, R: io::BufRead>(
429
139k
        &mut self,
430
139k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
431
139k
    ) -> error::Result<()> {
432
        // Fill as much of the tmp buffer as possible
433
139k
        let start = self.partial_input_buf.position() as usize;
434
139k
        let bytes_read =
435
139k
            rangecoder.read_into(&mut self.partial_input_buf.get_mut()[start..])? as u64;
436
139k
        self.partial_input_buf
437
139k
            .set_position(self.partial_input_buf.position() + bytes_read);
438
139k
        Ok(())
439
139k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::read_partial_input_buf::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::read_partial_input_buf::<&mut std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<_, _>>::read_partial_input_buf::<_>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::read_partial_input_buf::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
428
5
    fn read_partial_input_buf<'a, R: io::BufRead>(
429
5
        &mut self,
430
5
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
431
5
    ) -> error::Result<()> {
432
        // Fill as much of the tmp buffer as possible
433
5
        let start = self.partial_input_buf.position() as usize;
434
5
        let bytes_read =
435
5
            rangecoder.read_into(&mut self.partial_input_buf.get_mut()[start..])? as u64;
436
5
        self.partial_input_buf
437
5
            .set_position(self.partial_input_buf.position() + bytes_read);
438
5
        Ok(())
439
5
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::read_partial_input_buf::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
428
7.38k
    fn read_partial_input_buf<'a, R: io::BufRead>(
429
7.38k
        &mut self,
430
7.38k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
431
7.38k
    ) -> error::Result<()> {
432
        // Fill as much of the tmp buffer as possible
433
7.38k
        let start = self.partial_input_buf.position() as usize;
434
7.38k
        let bytes_read =
435
7.38k
            rangecoder.read_into(&mut self.partial_input_buf.get_mut()[start..])? as u64;
436
7.38k
        self.partial_input_buf
437
7.38k
            .set_position(self.partial_input_buf.position() + bytes_read);
438
7.38k
        Ok(())
439
7.38k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::read_partial_input_buf::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::read_partial_input_buf::<&mut std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::read_partial_input_buf::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
428
293
    fn read_partial_input_buf<'a, R: io::BufRead>(
429
293
        &mut self,
430
293
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
431
293
    ) -> error::Result<()> {
432
        // Fill as much of the tmp buffer as possible
433
293
        let start = self.partial_input_buf.position() as usize;
434
293
        let bytes_read =
435
293
            rangecoder.read_into(&mut self.partial_input_buf.get_mut()[start..])? as u64;
436
293
        self.partial_input_buf
437
293
            .set_position(self.partial_input_buf.position() + bytes_read);
438
293
        Ok(())
439
293
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::read_partial_input_buf::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
428
131k
    fn read_partial_input_buf<'a, R: io::BufRead>(
429
131k
        &mut self,
430
131k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
431
131k
    ) -> error::Result<()> {
432
        // Fill as much of the tmp buffer as possible
433
131k
        let start = self.partial_input_buf.position() as usize;
434
131k
        let bytes_read =
435
131k
            rangecoder.read_into(&mut self.partial_input_buf.get_mut()[start..])? as u64;
436
131k
        self.partial_input_buf
437
131k
            .set_position(self.partial_input_buf.position() + bytes_read);
438
131k
        Ok(())
439
131k
    }
440
441
98.4k
    fn process_mode<'a, R: io::BufRead>(
442
98.4k
        &mut self,
443
98.4k
        mut rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
444
98.4k
        mode: ProcessingMode,
445
98.4k
    ) -> error::Result<()> {
446
        loop {
447
3.66M
            if let Some(unpacked_size) = self.unpacked_size {
448
3.63M
                if self.output.len() as u64 >= unpacked_size {
449
10.3k
                    break;
450
3.62M
                }
451
34.9k
            } else if match mode {
452
                ProcessingMode::Partial => {
453
34.7k
                    rangecoder.is_eof()? && self.partial_input_buf.position() as usize == 0
454
                }
455
                ProcessingMode::Finish => {
456
234
                    rangecoder.is_finished_ok()? && self.partial_input_buf.position() as usize == 0
457
                }
458
            } {
459
517
                break;
460
34.4k
            }
461
462
3.65M
            if self.partial_input_buf.position() as usize > 0 {
463
86.9k
                self.read_partial_input_buf(rangecoder)?;
464
86.9k
                let tmp = *self.partial_input_buf.get_ref();
465
466
                // Check if we need more data to advance the decompressor
467
86.9k
                if mode == ProcessingMode::Partial
468
86.6k
                    && (self.partial_input_buf.position() as usize) < MAX_REQUIRED_INPUT
469
38.2k
                    && self
470
38.2k
                        .try_process_next(
471
38.2k
                            &tmp[..self.partial_input_buf.position() as usize],
472
38.2k
                            rangecoder.range,
473
38.2k
                            rangecoder.code,
474
38.2k
                        )
475
38.2k
                        .is_err()
476
                {
477
4.02k
                    return Ok(());
478
82.8k
                }
479
480
                // Run the decompressor on the tmp buffer
481
82.8k
                let mut tmp_reader =
482
82.8k
                    io::Cursor::new(&tmp[..self.partial_input_buf.position() as usize]);
483
82.8k
                let mut tmp_rangecoder = rangecoder::RangeDecoder::from_parts(
484
82.8k
                    &mut tmp_reader,
485
82.8k
                    rangecoder.range,
486
82.8k
                    rangecoder.code,
487
                );
488
82.8k
                let res = self.process_next(&mut tmp_rangecoder)?;
489
490
                // Update the actual rangecoder
491
74.5k
                rangecoder.set(tmp_rangecoder.range, tmp_rangecoder.code);
492
493
                // Update tmp buffer
494
74.5k
                let end = self.partial_input_buf.position();
495
74.5k
                let new_len = end - tmp_reader.position();
496
74.5k
                self.partial_input_buf.get_mut()[..new_len as usize]
497
74.5k
                    .copy_from_slice(&tmp[tmp_reader.position() as usize..end as usize]);
498
74.5k
                self.partial_input_buf.set_position(new_len);
499
500
74.5k
                if res == ProcessingStatus::Finished {
501
0
                    break;
502
74.5k
                };
503
            } else {
504
3.56M
                let buf: &[u8] = rangecoder.stream.fill_buf()?;
505
3.56M
                if mode == ProcessingMode::Partial
506
3.56M
                    && buf.len() < MAX_REQUIRED_INPUT
507
366k
                    && self
508
366k
                        .try_process_next(buf, rangecoder.range, rangecoder.code)
509
366k
                        .is_err()
510
                {
511
52.3k
                    return self.read_partial_input_buf(rangecoder);
512
3.51M
                }
513
514
3.51M
                if self.process_next(&mut rangecoder)? == ProcessingStatus::Finished {
515
3
                    break;
516
3.49M
                };
517
            }
518
        }
519
520
10.9k
        if let Some(len) = self.unpacked_size {
521
10.3k
            if mode == ProcessingMode::Finish && len != self.output.len() as u64 {
522
232
                return Err(error::Error::LzmaError(format!(
523
232
                    "Expected unpacked size of {} but decompressed to {}",
524
232
                    len,
525
232
                    self.output.len()
526
232
                )));
527
10.1k
            }
528
519
        }
529
530
10.6k
        Ok(())
531
98.4k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_mode::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_mode::<&mut std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<_, _>>::process_mode::<_>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_mode::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
441
18
    fn process_mode<'a, R: io::BufRead>(
442
18
        &mut self,
443
18
        mut rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
444
18
        mode: ProcessingMode,
445
18
    ) -> error::Result<()> {
446
        loop {
447
18
            if let Some(unpacked_size) = self.unpacked_size {
448
17
                if self.output.len() as u64 >= unpacked_size {
449
3
                    break;
450
14
                }
451
1
            } else if match mode {
452
                ProcessingMode::Partial => {
453
0
                    rangecoder.is_eof()? && self.partial_input_buf.position() as usize == 0
454
                }
455
                ProcessingMode::Finish => {
456
1
                    rangecoder.is_finished_ok()? && self.partial_input_buf.position() as usize == 0
457
                }
458
            } {
459
0
                break;
460
1
            }
461
462
15
            if self.partial_input_buf.position() as usize > 0 {
463
5
                self.read_partial_input_buf(rangecoder)?;
464
5
                let tmp = *self.partial_input_buf.get_ref();
465
466
                // Check if we need more data to advance the decompressor
467
5
                if mode == ProcessingMode::Partial
468
0
                    && (self.partial_input_buf.position() as usize) < MAX_REQUIRED_INPUT
469
0
                    && self
470
0
                        .try_process_next(
471
0
                            &tmp[..self.partial_input_buf.position() as usize],
472
0
                            rangecoder.range,
473
0
                            rangecoder.code,
474
0
                        )
475
0
                        .is_err()
476
                {
477
0
                    return Ok(());
478
5
                }
479
480
                // Run the decompressor on the tmp buffer
481
5
                let mut tmp_reader =
482
5
                    io::Cursor::new(&tmp[..self.partial_input_buf.position() as usize]);
483
5
                let mut tmp_rangecoder = rangecoder::RangeDecoder::from_parts(
484
5
                    &mut tmp_reader,
485
5
                    rangecoder.range,
486
5
                    rangecoder.code,
487
                );
488
5
                let res = self.process_next(&mut tmp_rangecoder)?;
489
490
                // Update the actual rangecoder
491
0
                rangecoder.set(tmp_rangecoder.range, tmp_rangecoder.code);
492
493
                // Update tmp buffer
494
0
                let end = self.partial_input_buf.position();
495
0
                let new_len = end - tmp_reader.position();
496
0
                self.partial_input_buf.get_mut()[..new_len as usize]
497
0
                    .copy_from_slice(&tmp[tmp_reader.position() as usize..end as usize]);
498
0
                self.partial_input_buf.set_position(new_len);
499
500
0
                if res == ProcessingStatus::Finished {
501
0
                    break;
502
0
                };
503
            } else {
504
10
                let buf: &[u8] = rangecoder.stream.fill_buf()?;
505
10
                if mode == ProcessingMode::Partial
506
0
                    && buf.len() < MAX_REQUIRED_INPUT
507
0
                    && self
508
0
                        .try_process_next(buf, rangecoder.range, rangecoder.code)
509
0
                        .is_err()
510
                {
511
0
                    return self.read_partial_input_buf(rangecoder);
512
10
                }
513
514
10
                if self.process_next(&mut rangecoder)? == ProcessingStatus::Finished {
515
0
                    break;
516
0
                };
517
            }
518
        }
519
520
3
        if let Some(len) = self.unpacked_size {
521
3
            if mode == ProcessingMode::Finish && len != self.output.len() as u64 {
522
0
                return Err(error::Error::LzmaError(format!(
523
0
                    "Expected unpacked size of {} but decompressed to {}",
524
0
                    len,
525
0
                    self.output.len()
526
0
                )));
527
3
            }
528
0
        }
529
530
3
        Ok(())
531
18
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_mode::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
441
6.55k
    fn process_mode<'a, R: io::BufRead>(
442
6.55k
        &mut self,
443
6.55k
        mut rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
444
6.55k
        mode: ProcessingMode,
445
6.55k
    ) -> error::Result<()> {
446
        loop {
447
106k
            if let Some(unpacked_size) = self.unpacked_size {
448
106k
                if self.output.len() as u64 >= unpacked_size {
449
92
                    break;
450
106k
                }
451
65
            } else if match mode {
452
                ProcessingMode::Partial => {
453
65
                    rangecoder.is_eof()? && self.partial_input_buf.position() as usize == 0
454
                }
455
                ProcessingMode::Finish => {
456
0
                    rangecoder.is_finished_ok()? && self.partial_input_buf.position() as usize == 0
457
                }
458
            } {
459
2
                break;
460
63
            }
461
462
106k
            if self.partial_input_buf.position() as usize > 0 {
463
4.61k
                self.read_partial_input_buf(rangecoder)?;
464
4.61k
                let tmp = *self.partial_input_buf.get_ref();
465
466
                // Check if we need more data to advance the decompressor
467
4.61k
                if mode == ProcessingMode::Partial
468
4.61k
                    && (self.partial_input_buf.position() as usize) < MAX_REQUIRED_INPUT
469
3.00k
                    && self
470
3.00k
                        .try_process_next(
471
3.00k
                            &tmp[..self.partial_input_buf.position() as usize],
472
3.00k
                            rangecoder.range,
473
3.00k
                            rangecoder.code,
474
3.00k
                        )
475
3.00k
                        .is_err()
476
                {
477
272
                    return Ok(());
478
4.34k
                }
479
480
                // Run the decompressor on the tmp buffer
481
4.34k
                let mut tmp_reader =
482
4.34k
                    io::Cursor::new(&tmp[..self.partial_input_buf.position() as usize]);
483
4.34k
                let mut tmp_rangecoder = rangecoder::RangeDecoder::from_parts(
484
4.34k
                    &mut tmp_reader,
485
4.34k
                    rangecoder.range,
486
4.34k
                    rangecoder.code,
487
                );
488
4.34k
                let res = self.process_next(&mut tmp_rangecoder)?;
489
490
                // Update the actual rangecoder
491
3.05k
                rangecoder.set(tmp_rangecoder.range, tmp_rangecoder.code);
492
493
                // Update tmp buffer
494
3.05k
                let end = self.partial_input_buf.position();
495
3.05k
                let new_len = end - tmp_reader.position();
496
3.05k
                self.partial_input_buf.get_mut()[..new_len as usize]
497
3.05k
                    .copy_from_slice(&tmp[tmp_reader.position() as usize..end as usize]);
498
3.05k
                self.partial_input_buf.set_position(new_len);
499
500
3.05k
                if res == ProcessingStatus::Finished {
501
0
                    break;
502
3.05k
                };
503
            } else {
504
101k
                let buf: &[u8] = rangecoder.stream.fill_buf()?;
505
101k
                if mode == ProcessingMode::Partial
506
101k
                    && buf.len() < MAX_REQUIRED_INPUT
507
21.2k
                    && self
508
21.2k
                        .try_process_next(buf, rangecoder.range, rangecoder.code)
509
21.2k
                        .is_err()
510
                {
511
2.77k
                    return self.read_partial_input_buf(rangecoder);
512
98.7k
                }
513
514
98.7k
                if self.process_next(&mut rangecoder)? == ProcessingStatus::Finished {
515
0
                    break;
516
96.6k
                };
517
            }
518
        }
519
520
94
        if let Some(len) = self.unpacked_size {
521
92
            if mode == ProcessingMode::Finish && len != self.output.len() as u64 {
522
0
                return Err(error::Error::LzmaError(format!(
523
0
                    "Expected unpacked size of {} but decompressed to {}",
524
0
                    len,
525
0
                    self.output.len()
526
0
                )));
527
92
            }
528
2
        }
529
530
94
        Ok(())
531
6.55k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_mode::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::process_mode::<&mut std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_mode::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
441
4.14k
    fn process_mode<'a, R: io::BufRead>(
442
4.14k
        &mut self,
443
4.14k
        mut rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
444
4.14k
        mode: ProcessingMode,
445
4.14k
    ) -> error::Result<()> {
446
        loop {
447
4.31k
            if let Some(unpacked_size) = self.unpacked_size {
448
4.08k
                if self.output.len() as u64 >= unpacked_size {
449
1.92k
                    break;
450
2.16k
                }
451
233
            } else if match mode {
452
                ProcessingMode::Partial => {
453
0
                    rangecoder.is_eof()? && self.partial_input_buf.position() as usize == 0
454
                }
455
                ProcessingMode::Finish => {
456
233
                    rangecoder.is_finished_ok()? && self.partial_input_buf.position() as usize == 0
457
                }
458
            } {
459
37
                break;
460
196
            }
461
462
2.35k
            if self.partial_input_buf.position() as usize > 0 {
463
293
                self.read_partial_input_buf(rangecoder)?;
464
293
                let tmp = *self.partial_input_buf.get_ref();
465
466
                // Check if we need more data to advance the decompressor
467
293
                if mode == ProcessingMode::Partial
468
0
                    && (self.partial_input_buf.position() as usize) < MAX_REQUIRED_INPUT
469
0
                    && self
470
0
                        .try_process_next(
471
0
                            &tmp[..self.partial_input_buf.position() as usize],
472
0
                            rangecoder.range,
473
0
                            rangecoder.code,
474
0
                        )
475
0
                        .is_err()
476
                {
477
0
                    return Ok(());
478
293
                }
479
480
                // Run the decompressor on the tmp buffer
481
293
                let mut tmp_reader =
482
293
                    io::Cursor::new(&tmp[..self.partial_input_buf.position() as usize]);
483
293
                let mut tmp_rangecoder = rangecoder::RangeDecoder::from_parts(
484
293
                    &mut tmp_reader,
485
293
                    rangecoder.range,
486
293
                    rangecoder.code,
487
                );
488
293
                let res = self.process_next(&mut tmp_rangecoder)?;
489
490
                // Update the actual rangecoder
491
0
                rangecoder.set(tmp_rangecoder.range, tmp_rangecoder.code);
492
493
                // Update tmp buffer
494
0
                let end = self.partial_input_buf.position();
495
0
                let new_len = end - tmp_reader.position();
496
0
                self.partial_input_buf.get_mut()[..new_len as usize]
497
0
                    .copy_from_slice(&tmp[tmp_reader.position() as usize..end as usize]);
498
0
                self.partial_input_buf.set_position(new_len);
499
500
0
                if res == ProcessingStatus::Finished {
501
0
                    break;
502
0
                };
503
            } else {
504
2.06k
                let buf: &[u8] = rangecoder.stream.fill_buf()?;
505
2.06k
                if mode == ProcessingMode::Partial
506
0
                    && buf.len() < MAX_REQUIRED_INPUT
507
0
                    && self
508
0
                        .try_process_next(buf, rangecoder.range, rangecoder.code)
509
0
                        .is_err()
510
                {
511
0
                    return self.read_partial_input_buf(rangecoder);
512
2.06k
                }
513
514
2.06k
                if self.process_next(&mut rangecoder)? == ProcessingStatus::Finished {
515
0
                    break;
516
174
                };
517
            }
518
        }
519
520
1.95k
        if let Some(len) = self.unpacked_size {
521
1.92k
            if mode == ProcessingMode::Finish && len != self.output.len() as u64 {
522
232
                return Err(error::Error::LzmaError(format!(
523
232
                    "Expected unpacked size of {} but decompressed to {}",
524
232
                    len,
525
232
                    self.output.len()
526
232
                )));
527
1.69k
            }
528
37
        }
529
530
1.72k
        Ok(())
531
4.14k
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::process_mode::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
441
87.7k
    fn process_mode<'a, R: io::BufRead>(
442
87.7k
        &mut self,
443
87.7k
        mut rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
444
87.7k
        mode: ProcessingMode,
445
87.7k
    ) -> error::Result<()> {
446
        loop {
447
3.55M
            if let Some(unpacked_size) = self.unpacked_size {
448
3.52M
                if self.output.len() as u64 >= unpacked_size {
449
8.37k
                    break;
450
3.51M
                }
451
34.6k
            } else if match mode {
452
                ProcessingMode::Partial => {
453
34.6k
                    rangecoder.is_eof()? && self.partial_input_buf.position() as usize == 0
454
                }
455
                ProcessingMode::Finish => {
456
0
                    rangecoder.is_finished_ok()? && self.partial_input_buf.position() as usize == 0
457
                }
458
            } {
459
478
                break;
460
34.1k
            }
461
462
3.54M
            if self.partial_input_buf.position() as usize > 0 {
463
82.0k
                self.read_partial_input_buf(rangecoder)?;
464
82.0k
                let tmp = *self.partial_input_buf.get_ref();
465
466
                // Check if we need more data to advance the decompressor
467
82.0k
                if mode == ProcessingMode::Partial
468
82.0k
                    && (self.partial_input_buf.position() as usize) < MAX_REQUIRED_INPUT
469
35.2k
                    && self
470
35.2k
                        .try_process_next(
471
35.2k
                            &tmp[..self.partial_input_buf.position() as usize],
472
35.2k
                            rangecoder.range,
473
35.2k
                            rangecoder.code,
474
35.2k
                        )
475
35.2k
                        .is_err()
476
                {
477
3.74k
                    return Ok(());
478
78.2k
                }
479
480
                // Run the decompressor on the tmp buffer
481
78.2k
                let mut tmp_reader =
482
78.2k
                    io::Cursor::new(&tmp[..self.partial_input_buf.position() as usize]);
483
78.2k
                let mut tmp_rangecoder = rangecoder::RangeDecoder::from_parts(
484
78.2k
                    &mut tmp_reader,
485
78.2k
                    rangecoder.range,
486
78.2k
                    rangecoder.code,
487
                );
488
78.2k
                let res = self.process_next(&mut tmp_rangecoder)?;
489
490
                // Update the actual rangecoder
491
71.5k
                rangecoder.set(tmp_rangecoder.range, tmp_rangecoder.code);
492
493
                // Update tmp buffer
494
71.5k
                let end = self.partial_input_buf.position();
495
71.5k
                let new_len = end - tmp_reader.position();
496
71.5k
                self.partial_input_buf.get_mut()[..new_len as usize]
497
71.5k
                    .copy_from_slice(&tmp[tmp_reader.position() as usize..end as usize]);
498
71.5k
                self.partial_input_buf.set_position(new_len);
499
500
71.5k
                if res == ProcessingStatus::Finished {
501
0
                    break;
502
71.5k
                };
503
            } else {
504
3.46M
                let buf: &[u8] = rangecoder.stream.fill_buf()?;
505
3.46M
                if mode == ProcessingMode::Partial
506
3.46M
                    && buf.len() < MAX_REQUIRED_INPUT
507
345k
                    && self
508
345k
                        .try_process_next(buf, rangecoder.range, rangecoder.code)
509
345k
                        .is_err()
510
                {
511
49.5k
                    return self.read_partial_input_buf(rangecoder);
512
3.41M
                }
513
514
3.41M
                if self.process_next(&mut rangecoder)? == ProcessingStatus::Finished {
515
3
                    break;
516
3.39M
                };
517
            }
518
        }
519
520
8.85k
        if let Some(len) = self.unpacked_size {
521
8.37k
            if mode == ProcessingMode::Finish && len != self.output.len() as u64 {
522
0
                return Err(error::Error::LzmaError(format!(
523
0
                    "Expected unpacked size of {} but decompressed to {}",
524
0
                    len,
525
0
                    self.output.len()
526
0
                )));
527
8.37k
            }
528
480
        }
529
530
8.85k
        Ok(())
531
87.7k
    }
532
533
3.22M
    fn decode_literal<'a, R: io::BufRead>(
534
3.22M
        &mut self,
535
3.22M
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
536
3.22M
        update: bool,
537
3.22M
    ) -> error::Result<u8> {
538
3.22M
        let def_prev_byte = 0u8;
539
3.22M
        let prev_byte = self.output.last_or(def_prev_byte) as usize;
540
541
3.22M
        let mut result: usize = 1;
542
3.22M
        let lit_state =
543
3.22M
            ((self.output.len() & ((1 << self.lp) - 1)) << self.lc) + (prev_byte >> (8 - self.lc));
544
3.22M
        let probs = &mut self.literal_probs[lit_state];
545
546
3.22M
        if self.state >= 7 {
547
85.8k
            let mut match_byte = self.output.last_n(self.rep[0] + 1)? as usize;
548
549
186k
            while result < 0x100 {
550
185k
                let match_bit = (match_byte >> 7) & 1;
551
185k
                match_byte <<= 1;
552
185k
                let bit = rangecoder
553
185k
                    .decode_bit(&mut probs[((1 + match_bit) << 8) + result], update)?
554
                    as usize;
555
184k
                result = (result << 1) ^ bit;
556
184k
                if match_bit != bit {
557
83.9k
                    break;
558
100k
                }
559
            }
560
3.13M
        }
561
562
28.7M
        while result < 0x100 {
563
25.5M
            result = (result << 1) ^ (rangecoder.decode_bit(&mut probs[result], update)? as usize);
564
        }
565
566
3.21M
        Ok((result - 0x100) as u8)
567
3.22M
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::decode_literal::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::decode_literal::<&mut std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<_, _>>::decode_literal::<_>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::decode_literal::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
533
17.5k
    fn decode_literal<'a, R: io::BufRead>(
534
17.5k
        &mut self,
535
17.5k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
536
17.5k
        update: bool,
537
17.5k
    ) -> error::Result<u8> {
538
17.5k
        let def_prev_byte = 0u8;
539
17.5k
        let prev_byte = self.output.last_or(def_prev_byte) as usize;
540
541
17.5k
        let mut result: usize = 1;
542
17.5k
        let lit_state =
543
17.5k
            ((self.output.len() & ((1 << self.lp) - 1)) << self.lc) + (prev_byte >> (8 - self.lc));
544
17.5k
        let probs = &mut self.literal_probs[lit_state];
545
546
17.5k
        if self.state >= 7 {
547
2.45k
            let mut match_byte = self.output.last_n(self.rep[0] + 1)? as usize;
548
549
8.41k
            while result < 0x100 {
550
8.38k
                let match_bit = (match_byte >> 7) & 1;
551
8.38k
                match_byte <<= 1;
552
8.38k
                let bit = rangecoder
553
8.38k
                    .decode_bit(&mut probs[((1 + match_bit) << 8) + result], update)?
554
                    as usize;
555
8.38k
                result = (result << 1) ^ bit;
556
8.38k
                if match_bit != bit {
557
2.42k
                    break;
558
5.95k
                }
559
            }
560
15.0k
        }
561
562
145k
        while result < 0x100 {
563
129k
            result = (result << 1) ^ (rangecoder.decode_bit(&mut probs[result], update)? as usize);
564
        }
565
566
16.2k
        Ok((result - 0x100) as u8)
567
17.5k
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::decode_literal::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
533
61.4k
    fn decode_literal<'a, R: io::BufRead>(
534
61.4k
        &mut self,
535
61.4k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
536
61.4k
        update: bool,
537
61.4k
    ) -> error::Result<u8> {
538
61.4k
        let def_prev_byte = 0u8;
539
61.4k
        let prev_byte = self.output.last_or(def_prev_byte) as usize;
540
541
61.4k
        let mut result: usize = 1;
542
61.4k
        let lit_state =
543
61.4k
            ((self.output.len() & ((1 << self.lp) - 1)) << self.lc) + (prev_byte >> (8 - self.lc));
544
61.4k
        let probs = &mut self.literal_probs[lit_state];
545
546
61.4k
        if self.state >= 7 {
547
2.08k
            let mut match_byte = self.output.last_n(self.rep[0] + 1)? as usize;
548
549
8.55k
            while result < 0x100 {
550
8.50k
                let match_bit = (match_byte >> 7) & 1;
551
8.50k
                match_byte <<= 1;
552
8.50k
                let bit = rangecoder
553
8.50k
                    .decode_bit(&mut probs[((1 + match_bit) << 8) + result], update)?
554
                    as usize;
555
8.50k
                result = (result << 1) ^ bit;
556
8.50k
                if match_bit != bit {
557
2.03k
                    break;
558
6.47k
                }
559
            }
560
59.3k
        }
561
562
544k
        while result < 0x100 {
563
483k
            result = (result << 1) ^ (rangecoder.decode_bit(&mut probs[result], update)? as usize);
564
        }
565
566
61.4k
        Ok((result - 0x100) as u8)
567
61.4k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::decode_literal::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::decode_literal::<&mut std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::decode_literal::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
533
166k
    fn decode_literal<'a, R: io::BufRead>(
534
166k
        &mut self,
535
166k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
536
166k
        update: bool,
537
166k
    ) -> error::Result<u8> {
538
166k
        let def_prev_byte = 0u8;
539
166k
        let prev_byte = self.output.last_or(def_prev_byte) as usize;
540
541
166k
        let mut result: usize = 1;
542
166k
        let lit_state =
543
166k
            ((self.output.len() & ((1 << self.lp) - 1)) << self.lc) + (prev_byte >> (8 - self.lc));
544
166k
        let probs = &mut self.literal_probs[lit_state];
545
546
166k
        if self.state >= 7 {
547
50.7k
            let mut match_byte = self.output.last_n(self.rep[0] + 1)? as usize;
548
549
109k
            while result < 0x100 {
550
108k
                let match_bit = (match_byte >> 7) & 1;
551
108k
                match_byte <<= 1;
552
108k
                let bit = rangecoder
553
108k
                    .decode_bit(&mut probs[((1 + match_bit) << 8) + result], update)?
554
                    as usize;
555
107k
                result = (result << 1) ^ bit;
556
107k
                if match_bit != bit {
557
49.1k
                    break;
558
58.6k
                }
559
            }
560
115k
        }
561
562
1.33M
        while result < 0x100 {
563
1.18M
            result = (result << 1) ^ (rangecoder.decode_bit(&mut probs[result], update)? as usize);
564
        }
565
566
152k
        Ok((result - 0x100) as u8)
567
166k
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::decode_literal::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
533
2.98M
    fn decode_literal<'a, R: io::BufRead>(
534
2.98M
        &mut self,
535
2.98M
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
536
2.98M
        update: bool,
537
2.98M
    ) -> error::Result<u8> {
538
2.98M
        let def_prev_byte = 0u8;
539
2.98M
        let prev_byte = self.output.last_or(def_prev_byte) as usize;
540
541
2.98M
        let mut result: usize = 1;
542
2.98M
        let lit_state =
543
2.98M
            ((self.output.len() & ((1 << self.lp) - 1)) << self.lc) + (prev_byte >> (8 - self.lc));
544
2.98M
        let probs = &mut self.literal_probs[lit_state];
545
546
2.98M
        if self.state >= 7 {
547
30.5k
            let mut match_byte = self.output.last_n(self.rep[0] + 1)? as usize;
548
549
60.1k
            while result < 0x100 {
550
59.8k
                let match_bit = (match_byte >> 7) & 1;
551
59.8k
                match_byte <<= 1;
552
59.8k
                let bit = rangecoder
553
59.8k
                    .decode_bit(&mut probs[((1 + match_bit) << 8) + result], update)?
554
                    as usize;
555
59.8k
                result = (result << 1) ^ bit;
556
59.8k
                if match_bit != bit {
557
30.2k
                    break;
558
29.6k
                }
559
            }
560
2.95M
        }
561
562
26.7M
        while result < 0x100 {
563
23.7M
            result = (result << 1) ^ (rangecoder.decode_bit(&mut probs[result], update)? as usize);
564
        }
565
566
2.98M
        Ok((result - 0x100) as u8)
567
2.98M
    }
568
569
84.5k
    fn decode_distance<'a, R: io::BufRead>(
570
84.5k
        &mut self,
571
84.5k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
572
84.5k
        length: usize,
573
84.5k
        update: bool,
574
84.5k
    ) -> error::Result<usize> {
575
84.5k
        let len_state = if length > 3 { 3 } else { length };
576
577
84.5k
        let pos_slot = self.pos_slot_decoder[len_state].parse(rangecoder, update)? as usize;
578
79.4k
        if pos_slot < 4 {
579
11.7k
            return Ok(pos_slot);
580
67.6k
        }
581
582
67.6k
        let num_direct_bits = (pos_slot >> 1) - 1;
583
67.6k
        let mut result = (2 ^ (pos_slot & 1)) << num_direct_bits;
584
585
67.6k
        if pos_slot < 14 {
586
17.2k
            result += rangecoder.parse_reverse_bit_tree(
587
17.2k
                num_direct_bits,
588
17.2k
                &mut self.pos_decoders,
589
17.2k
                result - pos_slot,
590
17.2k
                update,
591
1.98k
            )? as usize;
592
        } else {
593
50.4k
            result += (rangecoder.get(num_direct_bits - 4)? as usize) << 4;
594
46.1k
            result += self.align_decoder.parse_reverse(rangecoder, update)? as usize;
595
        }
596
597
58.0k
        Ok(result)
598
84.5k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::decode_distance::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::decode_distance::<&mut std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<_, _>>::decode_distance::<_>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::decode_distance::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
569
3.51k
    fn decode_distance<'a, R: io::BufRead>(
570
3.51k
        &mut self,
571
3.51k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
572
3.51k
        length: usize,
573
3.51k
        update: bool,
574
3.51k
    ) -> error::Result<usize> {
575
3.51k
        let len_state = if length > 3 { 3 } else { length };
576
577
3.51k
        let pos_slot = self.pos_slot_decoder[len_state].parse(rangecoder, update)? as usize;
578
3.43k
        if pos_slot < 4 {
579
430
            return Ok(pos_slot);
580
3.00k
        }
581
582
3.00k
        let num_direct_bits = (pos_slot >> 1) - 1;
583
3.00k
        let mut result = (2 ^ (pos_slot & 1)) << num_direct_bits;
584
585
3.00k
        if pos_slot < 14 {
586
126
            result += rangecoder.parse_reverse_bit_tree(
587
126
                num_direct_bits,
588
126
                &mut self.pos_decoders,
589
126
                result - pos_slot,
590
126
                update,
591
3
            )? as usize;
592
        } else {
593
2.88k
            result += (rangecoder.get(num_direct_bits - 4)? as usize) << 4;
594
2.14k
            result += self.align_decoder.parse_reverse(rangecoder, update)? as usize;
595
        }
596
597
1.79k
        Ok(result)
598
3.51k
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::decode_distance::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
569
2.79k
    fn decode_distance<'a, R: io::BufRead>(
570
2.79k
        &mut self,
571
2.79k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
572
2.79k
        length: usize,
573
2.79k
        update: bool,
574
2.79k
    ) -> error::Result<usize> {
575
2.79k
        let len_state = if length > 3 { 3 } else { length };
576
577
2.79k
        let pos_slot = self.pos_slot_decoder[len_state].parse(rangecoder, update)? as usize;
578
2.79k
        if pos_slot < 4 {
579
487
            return Ok(pos_slot);
580
2.31k
        }
581
582
2.31k
        let num_direct_bits = (pos_slot >> 1) - 1;
583
2.31k
        let mut result = (2 ^ (pos_slot & 1)) << num_direct_bits;
584
585
2.31k
        if pos_slot < 14 {
586
1.18k
            result += rangecoder.parse_reverse_bit_tree(
587
1.18k
                num_direct_bits,
588
1.18k
                &mut self.pos_decoders,
589
1.18k
                result - pos_slot,
590
1.18k
                update,
591
0
            )? as usize;
592
        } else {
593
1.12k
            result += (rangecoder.get(num_direct_bits - 4)? as usize) << 4;
594
1.12k
            result += self.align_decoder.parse_reverse(rangecoder, update)? as usize;
595
        }
596
597
2.31k
        Ok(result)
598
2.79k
    }
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::decode_distance::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: <lzma_rs::decode::lzma::DecoderState<suricata::lzma::LzmaOutput, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata::lzma::LzmaOutput>>>::decode_distance::<&mut std::io::cursor::Cursor<&[u8]>>
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::decode_distance::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
569
53.9k
    fn decode_distance<'a, R: io::BufRead>(
570
53.9k
        &mut self,
571
53.9k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
572
53.9k
        length: usize,
573
53.9k
        update: bool,
574
53.9k
    ) -> error::Result<usize> {
575
53.9k
        let len_state = if length > 3 { 3 } else { length };
576
577
53.9k
        let pos_slot = self.pos_slot_decoder[len_state].parse(rangecoder, update)? as usize;
578
48.9k
        if pos_slot < 4 {
579
6.03k
            return Ok(pos_slot);
580
42.9k
        }
581
582
42.9k
        let num_direct_bits = (pos_slot >> 1) - 1;
583
42.9k
        let mut result = (2 ^ (pos_slot & 1)) << num_direct_bits;
584
585
42.9k
        if pos_slot < 14 {
586
11.5k
            result += rangecoder.parse_reverse_bit_tree(
587
11.5k
                num_direct_bits,
588
11.5k
                &mut self.pos_decoders,
589
11.5k
                result - pos_slot,
590
11.5k
                update,
591
1.97k
            )? as usize;
592
        } else {
593
31.3k
            result += (rangecoder.get(num_direct_bits - 4)? as usize) << 4;
594
27.7k
            result += self.align_decoder.parse_reverse(rangecoder, update)? as usize;
595
        }
596
597
34.5k
        Ok(result)
598
53.9k
    }
<lzma_rs::decode::lzma::DecoderState<suricata_htp::decompressors::BlockingCursor, lzma_rs::decode::lzbuffer::LzCircularBuffer<suricata_htp::decompressors::BlockingCursor>>>::decode_distance::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
569
24.2k
    fn decode_distance<'a, R: io::BufRead>(
570
24.2k
        &mut self,
571
24.2k
        rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
572
24.2k
        length: usize,
573
24.2k
        update: bool,
574
24.2k
    ) -> error::Result<usize> {
575
24.2k
        let len_state = if length > 3 { 3 } else { length };
576
577
24.2k
        let pos_slot = self.pos_slot_decoder[len_state].parse(rangecoder, update)? as usize;
578
24.2k
        if pos_slot < 4 {
579
4.79k
            return Ok(pos_slot);
580
19.4k
        }
581
582
19.4k
        let num_direct_bits = (pos_slot >> 1) - 1;
583
19.4k
        let mut result = (2 ^ (pos_slot & 1)) << num_direct_bits;
584
585
19.4k
        if pos_slot < 14 {
586
4.35k
            result += rangecoder.parse_reverse_bit_tree(
587
4.35k
                num_direct_bits,
588
4.35k
                &mut self.pos_decoders,
589
4.35k
                result - pos_slot,
590
4.35k
                update,
591
0
            )? as usize;
592
        } else {
593
15.0k
            result += (rangecoder.get(num_direct_bits - 4)? as usize) << 4;
594
15.0k
            result += self.align_decoder.parse_reverse(rangecoder, update)? as usize;
595
        }
596
597
19.4k
        Ok(result)
598
24.2k
    }
599
}