@@ -41,7 +41,6 @@ use keccak_hash::keccak;
41
41
use kvdb:: DBTransaction ;
42
42
use log:: { debug, error, info, trace, warn} ;
43
43
use parking_lot:: { Mutex , RwLock , RwLockReadGuard } ;
44
- use snappy;
45
44
use trie_db:: TrieError ;
46
45
47
46
use crate :: { SnapshotClient , SnapshotWriter } ;
@@ -150,12 +149,15 @@ impl Restoration {
150
149
/// Feeds a chunk of state data to the Restoration. Aborts early if `flag` becomes false.
151
150
pub fn feed_state ( & mut self , hash : H256 , chunk : & [ u8 ] , flag : & AtomicBool ) -> Result < ( ) , Error > {
152
151
if self . state_chunks_left . contains ( & hash) {
153
- let expected_len = snappy :: decompressed_len ( chunk) ?;
152
+ let expected_len = snap :: raw :: decompress_len ( chunk) ?;
154
153
if expected_len > MAX_CHUNK_SIZE {
155
154
trace ! ( target: "snapshot" , "Discarding large chunk: {} vs {}" , expected_len, MAX_CHUNK_SIZE ) ;
156
155
return Err ( SnapshotError :: ChunkTooLarge . into ( ) ) ;
157
156
}
158
- let len = snappy:: decompress_into ( chunk, & mut self . snappy_buffer ) ?;
157
+ if self . snappy_buffer . len ( ) < expected_len {
158
+ self . snappy_buffer . resize_with ( expected_len, Default :: default) ;
159
+ }
160
+ let len = snap:: raw:: Decoder :: new ( ) . decompress ( chunk, & mut self . snappy_buffer ) ?;
159
161
160
162
self . state . feed ( & self . snappy_buffer [ ..len] , flag) ?;
161
163
@@ -173,12 +175,15 @@ impl Restoration {
173
175
/// Feeds a chunk of block data to the `Restoration`. Aborts early if `flag` becomes false.
174
176
pub fn feed_blocks ( & mut self , hash : H256 , chunk : & [ u8 ] , engine : & dyn Engine , flag : & AtomicBool ) -> Result < ( ) , Error > {
175
177
if self . block_chunks_left . contains ( & hash) {
176
- let expected_len = snappy :: decompressed_len ( chunk) ?;
178
+ let expected_len = snap :: raw :: decompress_len ( chunk) ?;
177
179
if expected_len > MAX_CHUNK_SIZE {
178
180
trace ! ( target: "snapshot" , "Discarding large chunk: {} vs {}" , expected_len, MAX_CHUNK_SIZE ) ;
179
181
return Err ( SnapshotError :: ChunkTooLarge . into ( ) ) ;
180
182
}
181
- let len = snappy:: decompress_into ( chunk, & mut self . snappy_buffer ) ?;
183
+ if self . snappy_buffer . len ( ) < expected_len {
184
+ self . snappy_buffer . resize_with ( expected_len, Default :: default) ;
185
+ }
186
+ let len = snap:: raw:: Decoder :: new ( ) . decompress ( chunk, & mut self . snappy_buffer ) ?;
182
187
183
188
self . secondary . feed ( & self . snappy_buffer [ ..len] , engine, flag) ?;
184
189
if let Some ( ref mut writer) = self . writer . as_mut ( ) {
0 commit comments