Show More
@@ -247,38 +247,45 b" impl<'a> RevlogEntry<'a> {" | |||||
247 | // Raw revision data follows. |
|
247 | // Raw revision data follows. | |
248 | b'u' => Ok(Cow::Borrowed(&self.bytes[1..])), |
|
248 | b'u' => Ok(Cow::Borrowed(&self.bytes[1..])), | |
249 | // zlib (RFC 1950) data. |
|
249 | // zlib (RFC 1950) data. | |
250 | b'x' => Ok(Cow::Owned(self.uncompressed_zlib_data())), |
|
250 | b'x' => Ok(Cow::Owned(self.uncompressed_zlib_data()?)), | |
251 | // zstd data. |
|
251 | // zstd data. | |
252 | b'\x28' => Ok(Cow::Owned(self.uncompressed_zstd_data())), |
|
252 | b'\x28' => Ok(Cow::Owned(self.uncompressed_zstd_data()?)), | |
253 | format_type => Err(RevlogError::UnknowDataFormat(format_type)), |
|
253 | format_type => Err(RevlogError::UnknowDataFormat(format_type)), | |
254 | } |
|
254 | } | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | fn uncompressed_zlib_data(&self) -> Vec<u8> { |
|
257 | fn uncompressed_zlib_data(&self) -> Result<Vec<u8>, RevlogError> { | |
258 | let mut decoder = ZlibDecoder::new(self.bytes); |
|
258 | let mut decoder = ZlibDecoder::new(self.bytes); | |
259 | if self.is_delta() { |
|
259 | if self.is_delta() { | |
260 | let mut buf = Vec::with_capacity(self.compressed_len); |
|
260 | let mut buf = Vec::with_capacity(self.compressed_len); | |
261 | decoder.read_to_end(&mut buf).expect("corrupted zlib data"); |
|
261 | decoder | |
262 | buf |
|
262 | .read_to_end(&mut buf) | |
|
263 | .or(Err(RevlogError::Corrupted))?; | |||
|
264 | Ok(buf) | |||
263 | } else { |
|
265 | } else { | |
264 | let mut buf = vec![0; self.uncompressed_len]; |
|
266 | let mut buf = vec![0; self.uncompressed_len]; | |
265 | decoder.read_exact(&mut buf).expect("corrupted zlib data"); |
|
267 | decoder | |
266 | buf |
|
268 | .read_exact(&mut buf) | |
|
269 | .or(Err(RevlogError::Corrupted))?; | |||
|
270 | Ok(buf) | |||
267 | } |
|
271 | } | |
268 | } |
|
272 | } | |
269 |
|
273 | |||
270 | fn uncompressed_zstd_data(&self) -> Vec<u8> { |
|
274 | fn uncompressed_zstd_data(&self) -> Result<Vec<u8>, RevlogError> { | |
271 | if self.is_delta() { |
|
275 | if self.is_delta() { | |
272 | let mut buf = Vec::with_capacity(self.compressed_len); |
|
276 | let mut buf = Vec::with_capacity(self.compressed_len); | |
273 | zstd::stream::copy_decode(self.bytes, &mut buf) |
|
277 | zstd::stream::copy_decode(self.bytes, &mut buf) | |
274 | .expect("corrupted zstd data"); |
|
278 | .or(Err(RevlogError::Corrupted))?; | |
275 | buf |
|
279 | Ok(buf) | |
276 | } else { |
|
280 | } else { | |
277 | let mut buf = vec![0; self.uncompressed_len]; |
|
281 | let mut buf = vec![0; self.uncompressed_len]; | |
278 | let len = zstd::block::decompress_to_buffer(self.bytes, &mut buf) |
|
282 | let len = zstd::block::decompress_to_buffer(self.bytes, &mut buf) | |
279 | .expect("corrupted zstd data"); |
|
283 | .or(Err(RevlogError::Corrupted))?; | |
280 |
|
|
284 | if len != self.uncompressed_len { | |
281 | buf |
|
285 | Err(RevlogError::Corrupted) | |
|
286 | } else { | |||
|
287 | Ok(buf) | |||
|
288 | } | |||
282 | } |
|
289 | } | |
283 | } |
|
290 | } | |
284 |
|
291 |
General Comments 0
You need to be logged in to leave comments.
Login now