/rust/registry/src/index.crates.io-1949cf8c6b5b557f/flate2-1.0.35/src/zio.rs
Line | Count | Source |
1 | | use std::io; |
2 | | use std::io::prelude::*; |
3 | | use std::mem; |
4 | | |
5 | | use crate::{Compress, Decompress, DecompressError, FlushCompress, FlushDecompress, Status}; |
6 | | |
7 | | #[derive(Debug)] |
8 | | pub struct Writer<W: Write, D: Ops> { |
9 | | obj: Option<W>, |
10 | | pub data: D, |
11 | | buf: Vec<u8>, |
12 | | } |
13 | | |
14 | | pub trait Ops { |
15 | | type Flush: Flush; |
16 | | fn total_in(&self) -> u64; |
17 | | fn total_out(&self) -> u64; |
18 | | fn run( |
19 | | &mut self, |
20 | | input: &[u8], |
21 | | output: &mut [u8], |
22 | | flush: Self::Flush, |
23 | | ) -> Result<Status, DecompressError>; |
24 | | fn run_vec( |
25 | | &mut self, |
26 | | input: &[u8], |
27 | | output: &mut Vec<u8>, |
28 | | flush: Self::Flush, |
29 | | ) -> Result<Status, DecompressError>; |
30 | | } |
31 | | |
32 | | impl Ops for Compress { |
33 | | type Flush = FlushCompress; |
34 | 0 | fn total_in(&self) -> u64 { |
35 | 0 | self.total_in() |
36 | 0 | } Unexecuted instantiation: <flate2::mem::Compress as flate2::zio::Ops>::total_in Unexecuted instantiation: <flate2::mem::Compress as flate2::zio::Ops>::total_in |
37 | 0 | fn total_out(&self) -> u64 { |
38 | 0 | self.total_out() |
39 | 0 | } Unexecuted instantiation: <flate2::mem::Compress as flate2::zio::Ops>::total_out Unexecuted instantiation: <flate2::mem::Compress as flate2::zio::Ops>::total_out |
40 | 0 | fn run( |
41 | 0 | &mut self, |
42 | 0 | input: &[u8], |
43 | 0 | output: &mut [u8], |
44 | 0 | flush: FlushCompress, |
45 | 0 | ) -> Result<Status, DecompressError> { |
46 | 0 | Ok(self.compress(input, output, flush).unwrap()) |
47 | 0 | } Unexecuted instantiation: <flate2::mem::Compress as flate2::zio::Ops>::run Unexecuted instantiation: <flate2::mem::Compress as flate2::zio::Ops>::run |
48 | 0 | fn run_vec( |
49 | 0 | &mut self, |
50 | 0 | input: &[u8], |
51 | 0 | output: &mut Vec<u8>, |
52 | 0 | flush: FlushCompress, |
53 | 0 | ) -> Result<Status, DecompressError> { |
54 | 0 | Ok(self.compress_vec(input, output, flush).unwrap()) |
55 | 0 | } Unexecuted instantiation: <flate2::mem::Compress as flate2::zio::Ops>::run_vec Unexecuted instantiation: <flate2::mem::Compress as flate2::zio::Ops>::run_vec |
56 | | } |
57 | | |
58 | | impl Ops for Decompress { |
59 | | type Flush = FlushDecompress; |
60 | 2.15M | fn total_in(&self) -> u64 { |
61 | 2.15M | self.total_in() |
62 | 2.15M | } <flate2::mem::Decompress as flate2::zio::Ops>::total_in Line | Count | Source | 60 | 3.91k | fn total_in(&self) -> u64 { | 61 | 3.91k | self.total_in() | 62 | 3.91k | } |
<flate2::mem::Decompress as flate2::zio::Ops>::total_in Line | Count | Source | 60 | 2.14M | fn total_in(&self) -> u64 { | 61 | 2.14M | self.total_in() | 62 | 2.14M | } |
|
63 | 4.40M | fn total_out(&self) -> u64 { |
64 | 4.40M | self.total_out() |
65 | 4.40M | } <flate2::mem::Decompress as flate2::zio::Ops>::total_out Line | Count | Source | 63 | 4.20k | fn total_out(&self) -> u64 { | 64 | 4.20k | self.total_out() | 65 | 4.20k | } |
<flate2::mem::Decompress as flate2::zio::Ops>::total_out Line | Count | Source | 63 | 4.40M | fn total_out(&self) -> u64 { | 64 | 4.40M | self.total_out() | 65 | 4.40M | } |
|
66 | 26.4k | fn run( |
67 | 26.4k | &mut self, |
68 | 26.4k | input: &[u8], |
69 | 26.4k | output: &mut [u8], |
70 | 26.4k | flush: FlushDecompress, |
71 | 26.4k | ) -> Result<Status, DecompressError> { |
72 | 26.4k | self.decompress(input, output, flush) |
73 | 26.4k | } Unexecuted instantiation: <flate2::mem::Decompress as flate2::zio::Ops>::run <flate2::mem::Decompress as flate2::zio::Ops>::run Line | Count | Source | 66 | 26.4k | fn run( | 67 | 26.4k | &mut self, | 68 | 26.4k | input: &[u8], | 69 | 26.4k | output: &mut [u8], | 70 | 26.4k | flush: FlushDecompress, | 71 | 26.4k | ) -> Result<Status, DecompressError> { | 72 | 26.4k | self.decompress(input, output, flush) | 73 | 26.4k | } |
|
74 | 6.15M | fn run_vec( |
75 | 6.15M | &mut self, |
76 | 6.15M | input: &[u8], |
77 | 6.15M | output: &mut Vec<u8>, |
78 | 6.15M | flush: FlushDecompress, |
79 | 6.15M | ) -> Result<Status, DecompressError> { |
80 | 6.15M | self.decompress_vec(input, output, flush) |
81 | 6.15M | } <flate2::mem::Decompress as flate2::zio::Ops>::run_vec Line | Count | Source | 74 | 5.57k | fn run_vec( | 75 | 5.57k | &mut self, | 76 | 5.57k | input: &[u8], | 77 | 5.57k | output: &mut Vec<u8>, | 78 | 5.57k | flush: FlushDecompress, | 79 | 5.57k | ) -> Result<Status, DecompressError> { | 80 | 5.57k | self.decompress_vec(input, output, flush) | 81 | 5.57k | } |
<flate2::mem::Decompress as flate2::zio::Ops>::run_vec Line | Count | Source | 74 | 6.14M | fn run_vec( | 75 | 6.14M | &mut self, | 76 | 6.14M | input: &[u8], | 77 | 6.14M | output: &mut Vec<u8>, | 78 | 6.14M | flush: FlushDecompress, | 79 | 6.14M | ) -> Result<Status, DecompressError> { | 80 | 6.14M | self.decompress_vec(input, output, flush) | 81 | 6.14M | } |
|
82 | | } |
83 | | |
84 | | pub trait Flush { |
85 | | fn none() -> Self; |
86 | | fn sync() -> Self; |
87 | | fn finish() -> Self; |
88 | | } |
89 | | |
90 | | impl Flush for FlushCompress { |
91 | 0 | fn none() -> Self { |
92 | 0 | FlushCompress::None |
93 | 0 | } Unexecuted instantiation: <flate2::mem::FlushCompress as flate2::zio::Flush>::none Unexecuted instantiation: <flate2::mem::FlushCompress as flate2::zio::Flush>::none |
94 | | |
95 | 0 | fn sync() -> Self { |
96 | 0 | FlushCompress::Sync |
97 | 0 | } Unexecuted instantiation: <flate2::mem::FlushCompress as flate2::zio::Flush>::sync Unexecuted instantiation: <flate2::mem::FlushCompress as flate2::zio::Flush>::sync |
98 | | |
99 | 0 | fn finish() -> Self { |
100 | 0 | FlushCompress::Finish |
101 | 0 | } Unexecuted instantiation: <flate2::mem::FlushCompress as flate2::zio::Flush>::finish Unexecuted instantiation: <flate2::mem::FlushCompress as flate2::zio::Flush>::finish |
102 | | } |
103 | | |
104 | | impl Flush for FlushDecompress { |
105 | 3.01M | fn none() -> Self { |
106 | 3.01M | FlushDecompress::None |
107 | 3.01M | } <flate2::mem::FlushDecompress as flate2::zio::Flush>::none Line | Count | Source | 105 | 2.92k | fn none() -> Self { | 106 | 2.92k | FlushDecompress::None | 107 | 2.92k | } |
<flate2::mem::FlushDecompress as flate2::zio::Flush>::none Line | Count | Source | 105 | 3.00M | fn none() -> Self { | 106 | 3.00M | FlushDecompress::None | 107 | 3.00M | } |
|
108 | | |
109 | 2.82M | fn sync() -> Self { |
110 | 2.82M | FlushDecompress::Sync |
111 | 2.82M | } <flate2::mem::FlushDecompress as flate2::zio::Flush>::sync Line | Count | Source | 109 | 973 | fn sync() -> Self { | 110 | 973 | FlushDecompress::Sync | 111 | 973 | } |
<flate2::mem::FlushDecompress as flate2::zio::Flush>::sync Line | Count | Source | 109 | 2.82M | fn sync() -> Self { | 110 | 2.82M | FlushDecompress::Sync | 111 | 2.82M | } |
|
112 | | |
113 | 339k | fn finish() -> Self { |
114 | 339k | FlushDecompress::Finish |
115 | 339k | } <flate2::mem::FlushDecompress as flate2::zio::Flush>::finish Line | Count | Source | 113 | 1.68k | fn finish() -> Self { | 114 | 1.68k | FlushDecompress::Finish | 115 | 1.68k | } |
<flate2::mem::FlushDecompress as flate2::zio::Flush>::finish Line | Count | Source | 113 | 338k | fn finish() -> Self { | 114 | 338k | FlushDecompress::Finish | 115 | 338k | } |
|
116 | | } |
117 | | |
118 | 32.0k | pub fn read<R, D>(obj: &mut R, data: &mut D, dst: &mut [u8]) -> io::Result<usize> |
119 | 32.0k | where |
120 | 32.0k | R: BufRead, |
121 | 32.0k | D: Ops, |
122 | | { |
123 | | loop { |
124 | | let (read, consumed, ret, eof); |
125 | | { |
126 | 34.7k | let input = obj.fill_buf()?; |
127 | 26.4k | eof = input.is_empty(); |
128 | 26.4k | let before_out = data.total_out(); |
129 | 26.4k | let before_in = data.total_in(); |
130 | 26.4k | let flush = if eof { |
131 | 0 | D::Flush::finish() |
132 | | } else { |
133 | 26.4k | D::Flush::none() |
134 | | }; |
135 | 26.4k | ret = data.run(input, dst, flush); |
136 | 26.4k | read = (data.total_out() - before_out) as usize; |
137 | 26.4k | consumed = (data.total_in() - before_in) as usize; |
138 | | } |
139 | 26.4k | obj.consume(consumed); |
140 | | |
141 | 16.6k | match ret { |
142 | | // If we haven't ready any data and we haven't hit EOF yet, |
143 | | // then we need to keep asking for more data because if we |
144 | | // return that 0 bytes of data have been read then it will |
145 | | // be interpreted as EOF. |
146 | 16.6k | Ok(Status::Ok | Status::BufError) if read == 0 && !eof && !dst.is_empty() => continue, |
147 | 18.2k | Ok(Status::Ok | Status::BufError | Status::StreamEnd) => return Ok(read), |
148 | | |
149 | | Err(..) => { |
150 | 5.59k | return Err(io::Error::new( |
151 | 5.59k | io::ErrorKind::InvalidInput, |
152 | 5.59k | "corrupt deflate stream", |
153 | 5.59k | )) |
154 | | } |
155 | | } |
156 | | } |
157 | 32.0k | } Unexecuted instantiation: flate2::zio::read::<flate2::bufreader::BufReader<suricata::http2::decompression::HTTP2cursor>, flate2::mem::Decompress> Unexecuted instantiation: flate2::zio::read::<&[u8], flate2::mem::Decompress> Unexecuted instantiation: flate2::zio::read::<_, _> flate2::zio::read::<flate2::bufreader::BufReader<suricata::http2::decompression::HTTP2cursor>, flate2::mem::Decompress> Line | Count | Source | 118 | 32.0k | pub fn read<R, D>(obj: &mut R, data: &mut D, dst: &mut [u8]) -> io::Result<usize> | 119 | 32.0k | where | 120 | 32.0k | R: BufRead, | 121 | 32.0k | D: Ops, | 122 | | { | 123 | | loop { | 124 | | let (read, consumed, ret, eof); | 125 | | { | 126 | 34.7k | let input = obj.fill_buf()?; | 127 | 26.4k | eof = input.is_empty(); | 128 | 26.4k | let before_out = data.total_out(); | 129 | 26.4k | let before_in = data.total_in(); | 130 | 26.4k | let flush = if eof { | 131 | 0 | D::Flush::finish() | 132 | | } else { | 133 | 26.4k | D::Flush::none() | 134 | | }; | 135 | 26.4k | ret = data.run(input, dst, flush); | 136 | 26.4k | read = (data.total_out() - before_out) as usize; | 137 | 26.4k | consumed = (data.total_in() - before_in) as usize; | 138 | | } | 139 | 26.4k | obj.consume(consumed); | 140 | | | 141 | 16.6k | match ret { | 142 | | // If we haven't ready any data and we haven't hit EOF yet, | 143 | | // then we need to keep asking for more data because if we | 144 | | // return that 0 bytes of data have been read then it will | 145 | | // be interpreted as EOF. | 146 | 16.6k | Ok(Status::Ok | Status::BufError) if read == 0 && !eof && !dst.is_empty() => continue, | 147 | 18.2k | Ok(Status::Ok | Status::BufError | Status::StreamEnd) => return Ok(read), | 148 | | | 149 | | Err(..) => { | 150 | 5.59k | return Err(io::Error::new( | 151 | 5.59k | io::ErrorKind::InvalidInput, | 152 | 5.59k | "corrupt deflate stream", | 153 | 5.59k | )) | 154 | | } | 155 | | } | 156 | | } | 157 | 32.0k | } |
flate2::zio::read::<&[u8], flate2::mem::Decompress> Line | Count | Source | 118 | 7 | pub fn read<R, D>(obj: &mut R, data: &mut D, dst: &mut [u8]) -> io::Result<usize> | 119 | 7 | where | 120 | 7 | R: BufRead, | 121 | 7 | D: Ops, | 122 | | { | 123 | | loop { | 124 | | let (read, consumed, ret, eof); | 125 | | { | 126 | 7 | let input = obj.fill_buf()?; | 127 | 7 | eof = input.is_empty(); | 128 | 7 | let before_out = data.total_out(); | 129 | 7 | let before_in = data.total_in(); | 130 | 7 | let flush = if eof { | 131 | 0 | D::Flush::finish() | 132 | | } else { | 133 | 7 | D::Flush::none() | 134 | | }; | 135 | 7 | ret = data.run(input, dst, flush); | 136 | 7 | read = (data.total_out() - before_out) as usize; | 137 | 7 | consumed = (data.total_in() - before_in) as usize; | 138 | | } | 139 | 7 | obj.consume(consumed); | 140 | | | 141 | 4 | match ret { | 142 | | // If we haven't ready any data and we haven't hit EOF yet, | 143 | | // then we need to keep asking for more data because if we | 144 | | // return that 0 bytes of data have been read then it will | 145 | | // be interpreted as EOF. | 146 | 4 | Ok(Status::Ok | Status::BufError) if read == 0 && !eof && !dst.is_empty() => continue, | 147 | 7 | Ok(Status::Ok | Status::BufError | Status::StreamEnd) => return Ok(read), | 148 | | | 149 | | Err(..) => { | 150 | 0 | return Err(io::Error::new( | 151 | 0 | io::ErrorKind::InvalidInput, | 152 | 0 | "corrupt deflate stream", | 153 | 0 | )) | 154 | | } | 155 | | } | 156 | | } | 157 | 7 | } |
Unexecuted instantiation: flate2::zio::read::<_, _> |
158 | | |
159 | | impl<W: Write, D: Ops> Writer<W, D> { |
160 | 305k | pub fn new(w: W, d: D) -> Writer<W, D> { |
161 | 305k | Writer { |
162 | 305k | obj: Some(w), |
163 | 305k | data: d, |
164 | 305k | buf: Vec::with_capacity(32 * 1024), |
165 | 305k | } |
166 | 305k | } <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::new Line | Count | Source | 160 | 1.68k | pub fn new(w: W, d: D) -> Writer<W, D> { | 161 | 1.68k | Writer { | 162 | 1.68k | obj: Some(w), | 163 | 1.68k | data: d, | 164 | 1.68k | buf: Vec::with_capacity(32 * 1024), | 165 | 1.68k | } | 166 | 1.68k | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::new <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::new Line | Count | Source | 160 | 304k | pub fn new(w: W, d: D) -> Writer<W, D> { | 161 | 304k | Writer { | 162 | 304k | obj: Some(w), | 163 | 304k | data: d, | 164 | 304k | buf: Vec::with_capacity(32 * 1024), | 165 | 304k | } | 166 | 304k | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::new |
167 | | |
168 | 342k | pub fn finish(&mut self) -> io::Result<()> { |
169 | | loop { |
170 | 342k | self.dump()?; |
171 | | |
172 | 339k | let before = self.data.total_out(); |
173 | 339k | self.data.run_vec(&[], &mut self.buf, D::Flush::finish())?; |
174 | 148k | if before == self.data.total_out() { |
175 | 148k | return Ok(()); |
176 | 0 | } |
177 | | } |
178 | 342k | } <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::finish Line | Count | Source | 168 | 1.68k | pub fn finish(&mut self) -> io::Result<()> { | 169 | | loop { | 170 | 1.68k | self.dump()?; | 171 | | | 172 | 1.68k | let before = self.data.total_out(); | 173 | 1.68k | self.data.run_vec(&[], &mut self.buf, D::Flush::finish())?; | 174 | 588 | if before == self.data.total_out() { | 175 | 588 | return Ok(()); | 176 | 0 | } | 177 | | } | 178 | 1.68k | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::finish <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::finish Line | Count | Source | 168 | 340k | pub fn finish(&mut self) -> io::Result<()> { | 169 | | loop { | 170 | 340k | self.dump()?; | 171 | | | 172 | 338k | let before = self.data.total_out(); | 173 | 338k | self.data.run_vec(&[], &mut self.buf, D::Flush::finish())?; | 174 | 147k | if before == self.data.total_out() { | 175 | 147k | return Ok(()); | 176 | 0 | } | 177 | | } | 178 | 340k | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::finish |
179 | | |
180 | 0 | pub fn replace(&mut self, w: W) -> W { |
181 | 0 | self.buf.truncate(0); |
182 | 0 | mem::replace(self.get_mut(), w) |
183 | 0 | } Unexecuted instantiation: <flate2::zio::Writer<_, _>>::replace Unexecuted instantiation: <flate2::zio::Writer<_, _>>::replace |
184 | | |
185 | 0 | pub fn get_ref(&self) -> &W { |
186 | 0 | self.obj.as_ref().unwrap() |
187 | 0 | } Unexecuted instantiation: <flate2::zio::Writer<_, _>>::get_ref Unexecuted instantiation: <flate2::zio::Writer<_, _>>::get_ref |
188 | | |
189 | 2.86M | pub fn get_mut(&mut self) -> &mut W { |
190 | 2.86M | self.obj.as_mut().unwrap() |
191 | 2.86M | } Unexecuted instantiation: <flate2::zio::Writer<_, _>>::get_mut <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::get_mut Line | Count | Source | 189 | 973 | pub fn get_mut(&mut self) -> &mut W { | 190 | 973 | self.obj.as_mut().unwrap() | 191 | 973 | } |
<flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::get_mut Line | Count | Source | 189 | 2.86M | pub fn get_mut(&mut self) -> &mut W { | 190 | 2.86M | self.obj.as_mut().unwrap() | 191 | 2.86M | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::get_mut |
192 | | |
193 | | // Note that this should only be called if the outer object is just about |
194 | | // to be consumed! |
195 | | // |
196 | | // (e.g. an implementation of `into_inner`) |
197 | 11.7k | pub fn take_inner(&mut self) -> W { |
198 | 11.7k | self.obj.take().unwrap() |
199 | 11.7k | } <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::take_inner Line | Count | Source | 197 | 6 | pub fn take_inner(&mut self) -> W { | 198 | 6 | self.obj.take().unwrap() | 199 | 6 | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::take_inner <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::take_inner Line | Count | Source | 197 | 11.7k | pub fn take_inner(&mut self) -> W { | 198 | 11.7k | self.obj.take().unwrap() | 199 | 11.7k | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::take_inner |
200 | | |
201 | 0 | pub fn is_present(&self) -> bool { |
202 | 0 | self.obj.is_some() |
203 | 0 | } Unexecuted instantiation: <flate2::zio::Writer<_, _>>::is_present Unexecuted instantiation: <flate2::zio::Writer<_, _>>::is_present |
204 | | |
205 | | // Returns total written bytes and status of underlying codec |
206 | 1.29M | pub(crate) fn write_with_status(&mut self, buf: &[u8]) -> io::Result<(usize, Status)> { |
207 | | // miniz isn't guaranteed to actually write any of the buffer provided, |
208 | | // it may be in a flushing mode where it's just giving us data before |
209 | | // we're actually giving it any data. We don't want to spuriously return |
210 | | // `Ok(0)` when possible as it will cause calls to write_all() to fail. |
211 | | // As a result we execute this in a loop to ensure that we try our |
212 | | // darndest to write the data. |
213 | | loop { |
214 | 1.29M | self.dump()?; |
215 | | |
216 | 1.05M | let before_in = self.data.total_in(); |
217 | 1.05M | let ret = self.data.run_vec(buf, &mut self.buf, D::Flush::none()); |
218 | 1.05M | let written = (self.data.total_in() - before_in) as usize; |
219 | 1.05M | let is_stream_end = matches!(ret, Ok(Status::StreamEnd)); |
220 | | |
221 | 1.05M | if !buf.is_empty() && written == 0 && ret.is_ok() && !is_stream_end { |
222 | 0 | continue; |
223 | 1.05M | } |
224 | 1.05M | return match ret { |
225 | 875k | Ok(st) => match st { |
226 | 875k | Status::Ok | Status::BufError | Status::StreamEnd => Ok((written, st)), |
227 | | }, |
228 | 174k | Err(..) => Err(io::Error::new( |
229 | 174k | io::ErrorKind::InvalidInput, |
230 | 174k | "corrupt deflate stream", |
231 | 174k | )), |
232 | | }; |
233 | | } |
234 | 1.29M | } <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::write_with_status Line | Count | Source | 206 | 1.95k | pub(crate) fn write_with_status(&mut self, buf: &[u8]) -> io::Result<(usize, Status)> { | 207 | | // miniz isn't guaranteed to actually write any of the buffer provided, | 208 | | // it may be in a flushing mode where it's just giving us data before | 209 | | // we're actually giving it any data. We don't want to spuriously return | 210 | | // `Ok(0)` when possible as it will cause calls to write_all() to fail. | 211 | | // As a result we execute this in a loop to ensure that we try our | 212 | | // darndest to write the data. | 213 | | loop { | 214 | 1.95k | self.dump()?; | 215 | | | 216 | 1.95k | let before_in = self.data.total_in(); | 217 | 1.95k | let ret = self.data.run_vec(buf, &mut self.buf, D::Flush::none()); | 218 | 1.95k | let written = (self.data.total_in() - before_in) as usize; | 219 | 1.95k | let is_stream_end = matches!(ret, Ok(Status::StreamEnd)); | 220 | | | 221 | 1.95k | if !buf.is_empty() && written == 0 && ret.is_ok() && !is_stream_end { | 222 | 0 | continue; | 223 | 1.95k | } | 224 | 1.95k | return match ret { | 225 | 860 | Ok(st) => match st { | 226 | 860 | Status::Ok | Status::BufError | Status::StreamEnd => Ok((written, st)), | 227 | | }, | 228 | 1.09k | Err(..) => Err(io::Error::new( | 229 | 1.09k | io::ErrorKind::InvalidInput, | 230 | 1.09k | "corrupt deflate stream", | 231 | 1.09k | )), | 232 | | }; | 233 | | } | 234 | 1.95k | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::write_with_status <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::write_with_status Line | Count | Source | 206 | 1.29M | pub(crate) fn write_with_status(&mut self, buf: &[u8]) -> io::Result<(usize, Status)> { | 207 | | // miniz isn't guaranteed to actually write any of the buffer provided, | 208 | | // it may be in a flushing mode where it's just giving us data before | 209 | | // we're actually giving it any data. We don't want to spuriously return | 210 | | // `Ok(0)` when possible as it will cause calls to write_all() to fail. | 211 | | // As a result we execute this in a loop to ensure that we try our | 212 | | // darndest to write the data. | 213 | | loop { | 214 | 1.29M | self.dump()?; | 215 | | | 216 | 1.04M | let before_in = self.data.total_in(); | 217 | 1.04M | let ret = self.data.run_vec(buf, &mut self.buf, D::Flush::none()); | 218 | 1.04M | let written = (self.data.total_in() - before_in) as usize; | 219 | 1.04M | let is_stream_end = matches!(ret, Ok(Status::StreamEnd)); | 220 | | | 221 | 1.04M | if !buf.is_empty() && written == 0 && ret.is_ok() && !is_stream_end { | 222 | 0 | continue; | 223 | 1.04M | } | 224 | 1.04M | return match ret { | 225 | 875k | Ok(st) => match st { | 226 | 875k | Status::Ok | Status::BufError | Status::StreamEnd => Ok((written, st)), | 227 | | }, | 228 | 173k | Err(..) => Err(io::Error::new( | 229 | 173k | io::ErrorKind::InvalidInput, | 230 | 173k | "corrupt deflate stream", | 231 | 173k | )), | 232 | | }; | 233 | | } | 234 | 1.29M | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::write_with_status |
235 | | |
236 | 4.46M | fn dump(&mut self) -> io::Result<()> { |
237 | | // TODO: should manage this buffer not with `drain` but probably more of |
238 | | // a deque-like strategy. |
239 | 6.03M | while !self.buf.is_empty() { |
240 | 2.70M | let n = self.obj.as_mut().unwrap().write(&self.buf)?; |
241 | 1.56M | if n == 0 { |
242 | 0 | return Err(io::ErrorKind::WriteZero.into()); |
243 | 1.56M | } |
244 | 1.56M | self.buf.drain(..n); |
245 | | } |
246 | 3.32M | Ok(()) |
247 | 4.46M | } <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::dump Line | Count | Source | 236 | 4.61k | fn dump(&mut self) -> io::Result<()> { | 237 | | // TODO: should manage this buffer not with `drain` but probably more of | 238 | | // a deque-like strategy. | 239 | 5.28k | while !self.buf.is_empty() { | 240 | 676 | let n = self.obj.as_mut().unwrap().write(&self.buf)?; | 241 | 667 | if n == 0 { | 242 | 0 | return Err(io::ErrorKind::WriteZero.into()); | 243 | 667 | } | 244 | 667 | self.buf.drain(..n); | 245 | | } | 246 | 4.60k | Ok(()) | 247 | 4.61k | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::dump <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress>>::dump Line | Count | Source | 236 | 4.45M | fn dump(&mut self) -> io::Result<()> { | 237 | | // TODO: should manage this buffer not with `drain` but probably more of | 238 | | // a deque-like strategy. | 239 | 6.02M | while !self.buf.is_empty() { | 240 | 2.70M | let n = self.obj.as_mut().unwrap().write(&self.buf)?; | 241 | 1.56M | if n == 0 { | 242 | 0 | return Err(io::ErrorKind::WriteZero.into()); | 243 | 1.56M | } | 244 | 1.56M | self.buf.drain(..n); | 245 | | } | 246 | 3.31M | Ok(()) | 247 | 4.45M | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _>>::dump |
248 | | } |
249 | | |
250 | | impl<W: Write, D: Ops> Write for Writer<W, D> { |
251 | 1.29M | fn write(&mut self, buf: &[u8]) -> io::Result<usize> { |
252 | 1.29M | self.write_with_status(buf).map(|res| res.0) |
253 | 1.29M | } Unexecuted instantiation: <flate2::zio::Writer<_, _> as std::io::Write>::write <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress> as std::io::Write>::write Line | Count | Source | 251 | 1.95k | fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | 252 | 1.95k | self.write_with_status(buf).map(|res| res.0) | 253 | 1.95k | } |
<flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress> as std::io::Write>::write Line | Count | Source | 251 | 1.29M | fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | 252 | 1.29M | self.write_with_status(buf).map(|res| res.0) | 253 | 1.29M | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _> as std::io::Write>::write |
254 | | |
255 | 2.82M | fn flush(&mut self) -> io::Result<()> { |
256 | 2.82M | self.data |
257 | 2.82M | .run_vec(&[], &mut self.buf, D::Flush::sync()) |
258 | 2.82M | .unwrap(); |
259 | | |
260 | | // Unfortunately miniz doesn't actually tell us when we're done with |
261 | | // pulling out all the data from the internal stream. To remedy this we |
262 | | // have to continually ask the stream for more memory until it doesn't |
263 | | // give us a chunk of memory the same size as our own internal buffer, |
264 | | // at which point we assume it's reached the end. |
265 | | loop { |
266 | 2.82M | self.dump()?; |
267 | 1.93M | let before = self.data.total_out(); |
268 | 1.93M | self.data |
269 | 1.93M | .run_vec(&[], &mut self.buf, D::Flush::none()) |
270 | 1.93M | .unwrap(); |
271 | 1.93M | if before == self.data.total_out() { |
272 | 1.93M | break; |
273 | 0 | } |
274 | | } |
275 | | |
276 | 1.93M | self.obj.as_mut().unwrap().flush() |
277 | 2.82M | } <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress> as std::io::Write>::flush Line | Count | Source | 255 | 973 | fn flush(&mut self) -> io::Result<()> { | 256 | 973 | self.data | 257 | 973 | .run_vec(&[], &mut self.buf, D::Flush::sync()) | 258 | 973 | .unwrap(); | 259 | | | 260 | | // Unfortunately miniz doesn't actually tell us when we're done with | 261 | | // pulling out all the data from the internal stream. To remedy this we | 262 | | // have to continually ask the stream for more memory until it doesn't | 263 | | // give us a chunk of memory the same size as our own internal buffer, | 264 | | // at which point we assume it's reached the end. | 265 | | loop { | 266 | 973 | self.dump()?; | 267 | 965 | let before = self.data.total_out(); | 268 | 965 | self.data | 269 | 965 | .run_vec(&[], &mut self.buf, D::Flush::none()) | 270 | 965 | .unwrap(); | 271 | 965 | if before == self.data.total_out() { | 272 | 965 | break; | 273 | 0 | } | 274 | | } | 275 | | | 276 | 965 | self.obj.as_mut().unwrap().flush() | 277 | 973 | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _> as std::io::Write>::flush <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress> as std::io::Write>::flush Line | Count | Source | 255 | 2.82M | fn flush(&mut self) -> io::Result<()> { | 256 | 2.82M | self.data | 257 | 2.82M | .run_vec(&[], &mut self.buf, D::Flush::sync()) | 258 | 2.82M | .unwrap(); | 259 | | | 260 | | // Unfortunately miniz doesn't actually tell us when we're done with | 261 | | // pulling out all the data from the internal stream. To remedy this we | 262 | | // have to continually ask the stream for more memory until it doesn't | 263 | | // give us a chunk of memory the same size as our own internal buffer, | 264 | | // at which point we assume it's reached the end. | 265 | | loop { | 266 | 2.82M | self.dump()?; | 267 | 1.93M | let before = self.data.total_out(); | 268 | 1.93M | self.data | 269 | 1.93M | .run_vec(&[], &mut self.buf, D::Flush::none()) | 270 | 1.93M | .unwrap(); | 271 | 1.93M | if before == self.data.total_out() { | 272 | 1.93M | break; | 273 | 0 | } | 274 | | } | 275 | | | 276 | 1.93M | self.obj.as_mut().unwrap().flush() | 277 | 2.82M | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _> as std::io::Write>::flush |
278 | | } |
279 | | |
280 | | impl<W: Write, D: Ops> Drop for Writer<W, D> { |
281 | 305k | fn drop(&mut self) { |
282 | 305k | if self.obj.is_some() { |
283 | 294k | let _ = self.finish(); |
284 | 294k | } |
285 | 305k | } <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress> as core::ops::drop::Drop>::drop Line | Count | Source | 281 | 1.68k | fn drop(&mut self) { | 282 | 1.68k | if self.obj.is_some() { | 283 | 1.67k | let _ = self.finish(); | 284 | 1.67k | } | 285 | 1.68k | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _> as core::ops::drop::Drop>::drop <flate2::zio::Writer<suricata_htp::decompressors::BlockingCursor, flate2::mem::Decompress> as core::ops::drop::Drop>::drop Line | Count | Source | 281 | 304k | fn drop(&mut self) { | 282 | 304k | if self.obj.is_some() { | 283 | 292k | let _ = self.finish(); | 284 | 292k | } | 285 | 304k | } |
Unexecuted instantiation: <flate2::zio::Writer<_, _> as core::ops::drop::Drop>::drop |
286 | | } |