##// END OF EJS Templates
rhg: RevlogEntry::uncompressed_len is signed...
Simon Sapin -
r49375:0a4ac916 default
parent child Browse files
Show More
@@ -118,7 +118,7 b' impl Index {'
118 offset_override: None,
118 offset_override: None,
119 };
119 };
120
120
121 offset += INDEX_ENTRY_SIZE + entry.compressed_len();
121 offset += INDEX_ENTRY_SIZE + entry.compressed_len() as usize;
122 }
122 }
123
123
124 if offset == bytes.len() {
124 if offset == bytes.len() {
@@ -261,13 +261,13 b" impl<'a> IndexEntry<'a> {"
261 }
261 }
262
262
263 /// Return the compressed length of the data.
263 /// Return the compressed length of the data.
264 pub fn compressed_len(&self) -> usize {
264 pub fn compressed_len(&self) -> u32 {
265 BigEndian::read_u32(&self.bytes[8..=11]) as usize
265 BigEndian::read_u32(&self.bytes[8..=11])
266 }
266 }
267
267
268 /// Return the uncompressed length of the data.
268 /// Return the uncompressed length of the data.
269 pub fn uncompressed_len(&self) -> usize {
269 pub fn uncompressed_len(&self) -> i32 {
270 BigEndian::read_u32(&self.bytes[12..=15]) as usize
270 BigEndian::read_i32(&self.bytes[12..=15])
271 }
271 }
272
272
273 /// Return the revision upon which the data has been derived.
273 /// Return the revision upon which the data has been derived.
@@ -1,4 +1,5 b''
1 use std::borrow::Cow;
1 use std::borrow::Cow;
2 use std::convert::TryFrom;
2 use std::io::Read;
3 use std::io::Read;
3 use std::ops::Deref;
4 use std::ops::Deref;
4 use std::path::Path;
5 use std::path::Path;
@@ -259,7 +260,7 b' impl Revlog {'
259 .get_entry(rev)
260 .get_entry(rev)
260 .ok_or(RevlogError::InvalidRevision)?;
261 .ok_or(RevlogError::InvalidRevision)?;
261 let start = index_entry.offset();
262 let start = index_entry.offset();
262 let end = start + index_entry.compressed_len();
263 let end = start + index_entry.compressed_len() as usize;
263 let data = if self.index.is_inline() {
264 let data = if self.index.is_inline() {
264 self.index.data(start, end)
265 self.index.data(start, end)
265 } else {
266 } else {
@@ -300,8 +301,8 b" pub struct RevlogEntry<'a> {"
300 revlog: &'a Revlog,
301 revlog: &'a Revlog,
301 rev: Revision,
302 rev: Revision,
302 bytes: &'a [u8],
303 bytes: &'a [u8],
303 compressed_len: usize,
304 compressed_len: u32,
304 uncompressed_len: usize,
305 uncompressed_len: i32,
305 base_rev_or_base_of_delta_chain: Option<Revision>,
306 base_rev_or_base_of_delta_chain: Option<Revision>,
306 }
307 }
307
308
@@ -310,6 +311,10 b" impl<'a> RevlogEntry<'a> {"
310 self.rev
311 self.rev
311 }
312 }
312
313
314 pub fn uncompressed_len(&self) -> Option<u32> {
315 u32::try_from(self.uncompressed_len).ok()
316 }
317
313 /// The data for this entry, after resolving deltas if any.
318 /// The data for this entry, after resolving deltas if any.
314 pub fn data(&self) -> Result<Cow<'a, [u8]>, HgError> {
319 pub fn data(&self) -> Result<Cow<'a, [u8]>, HgError> {
315 let mut entry = self.clone();
320 let mut entry = self.clone();
@@ -379,11 +384,12 b" impl<'a> RevlogEntry<'a> {"
379 fn uncompressed_zlib_data(&self) -> Result<Vec<u8>, HgError> {
384 fn uncompressed_zlib_data(&self) -> Result<Vec<u8>, HgError> {
380 let mut decoder = ZlibDecoder::new(self.bytes);
385 let mut decoder = ZlibDecoder::new(self.bytes);
381 if self.is_delta() {
386 if self.is_delta() {
382 let mut buf = Vec::with_capacity(self.compressed_len);
387 let mut buf = Vec::with_capacity(self.compressed_len as usize);
383 decoder.read_to_end(&mut buf).map_err(|_| corrupted())?;
388 decoder.read_to_end(&mut buf).map_err(|_| corrupted())?;
384 Ok(buf)
389 Ok(buf)
385 } else {
390 } else {
386 let mut buf = vec![0; self.uncompressed_len];
391 let cap = self.uncompressed_len.max(0) as usize;
392 let mut buf = vec![0; cap];
387 decoder.read_exact(&mut buf).map_err(|_| corrupted())?;
393 decoder.read_exact(&mut buf).map_err(|_| corrupted())?;
388 Ok(buf)
394 Ok(buf)
389 }
395 }
@@ -391,15 +397,16 b" impl<'a> RevlogEntry<'a> {"
391
397
392 fn uncompressed_zstd_data(&self) -> Result<Vec<u8>, HgError> {
398 fn uncompressed_zstd_data(&self) -> Result<Vec<u8>, HgError> {
393 if self.is_delta() {
399 if self.is_delta() {
394 let mut buf = Vec::with_capacity(self.compressed_len);
400 let mut buf = Vec::with_capacity(self.compressed_len as usize);
395 zstd::stream::copy_decode(self.bytes, &mut buf)
401 zstd::stream::copy_decode(self.bytes, &mut buf)
396 .map_err(|_| corrupted())?;
402 .map_err(|_| corrupted())?;
397 Ok(buf)
403 Ok(buf)
398 } else {
404 } else {
399 let mut buf = vec![0; self.uncompressed_len];
405 let cap = self.uncompressed_len.max(0) as usize;
406 let mut buf = vec![0; cap];
400 let len = zstd::block::decompress_to_buffer(self.bytes, &mut buf)
407 let len = zstd::block::decompress_to_buffer(self.bytes, &mut buf)
401 .map_err(|_| corrupted())?;
408 .map_err(|_| corrupted())?;
402 if len != self.uncompressed_len {
409 if len != self.uncompressed_len as usize {
403 Err(corrupted())
410 Err(corrupted())
404 } else {
411 } else {
405 Ok(buf)
412 Ok(buf)
General Comments 0
You need to be logged in to leave comments. Login now