Show More
@@ -247,38 +247,45 b" impl<'a> RevlogEntry<'a> {" | |||
|
247 | 247 | // Raw revision data follows. |
|
248 | 248 | b'u' => Ok(Cow::Borrowed(&self.bytes[1..])), |
|
249 | 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 | 251 | // zstd data. |
|
252 | b'\x28' => Ok(Cow::Owned(self.uncompressed_zstd_data())), | |
|
252 | b'\x28' => Ok(Cow::Owned(self.uncompressed_zstd_data()?)), | |
|
253 | 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 | 258 | let mut decoder = ZlibDecoder::new(self.bytes); |
|
259 | 259 | if self.is_delta() { |
|
260 | 260 | let mut buf = Vec::with_capacity(self.compressed_len); |
|
261 | decoder.read_to_end(&mut buf).expect("corrupted zlib data"); | |
|
262 | buf | |
|
261 | decoder | |
|
262 | .read_to_end(&mut buf) | |
|
263 | .or(Err(RevlogError::Corrupted))?; | |
|
264 | Ok(buf) | |
|
263 | 265 | } else { |
|
264 | 266 | let mut buf = vec![0; self.uncompressed_len]; |
|
265 | decoder.read_exact(&mut buf).expect("corrupted zlib data"); | |
|
266 | buf | |
|
267 | decoder | |
|
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 | 275 | if self.is_delta() { |
|
272 | 276 | let mut buf = Vec::with_capacity(self.compressed_len); |
|
273 | 277 | zstd::stream::copy_decode(self.bytes, &mut buf) |
|
274 | .expect("corrupted zstd data"); | |
|
275 | buf | |
|
278 | .or(Err(RevlogError::Corrupted))?; | |
|
279 | Ok(buf) | |
|
276 | 280 | } else { |
|
277 | 281 | let mut buf = vec![0; self.uncompressed_len]; |
|
278 | 282 | let len = zstd::block::decompress_to_buffer(self.bytes, &mut buf) |
|
279 | .expect("corrupted zstd data"); | |
|
280 |
|
|
|
281 | buf | |
|
283 | .or(Err(RevlogError::Corrupted))?; | |
|
284 | if len != self.uncompressed_len { | |
|
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