Show More
@@ -61,12 +61,21 b" pub fn parse_dirstate_entries<'a>(" | |||
|
61 | 61 | Option<&'a HgPath>, |
|
62 | 62 | ) -> Result<(), HgError>, |
|
63 | 63 | ) -> Result<&'a DirstateParents, HgError> { |
|
64 | let (parents, rest) = DirstateParents::from_bytes(contents) | |
|
65 | .map_err(|_| HgError::corrupted("Too little data for dirstate."))?; | |
|
64 | let mut entry_idx = 0; | |
|
65 | let original_len = contents.len(); | |
|
66 | let (parents, rest) = | |
|
67 | DirstateParents::from_bytes(contents).map_err(|_| { | |
|
68 | HgError::corrupted(format!( | |
|
69 | "Too little data for dirstate: {} bytes.", | |
|
70 | original_len | |
|
71 | )) | |
|
72 | })?; | |
|
66 | 73 | contents = rest; |
|
67 | 74 | while !contents.is_empty() { |
|
68 | 75 | let (raw_entry, rest) = RawEntry::from_bytes(contents) |
|
69 |
.map_err(|_| HgError::corrupted( |
|
|
76 | .map_err(|_| HgError::corrupted(format!( | |
|
77 | "dirstate corrupted: ran out of bytes at entry header {}, offset {}.", | |
|
78 | entry_idx, original_len-contents.len())))?; | |
|
70 | 79 | |
|
71 | 80 | let entry = DirstateEntry::from_v1_data( |
|
72 | 81 | EntryState::try_from(raw_entry.state)?, |
@@ -74,9 +83,14 b" pub fn parse_dirstate_entries<'a>(" | |||
|
74 | 83 | raw_entry.size.get(), |
|
75 | 84 | raw_entry.mtime.get(), |
|
76 | 85 | ); |
|
86 | let filename_len = raw_entry.length.get() as usize; | |
|
77 | 87 | let (paths, rest) = |
|
78 |
u8::slice_from_bytes(rest, |
|
|
79 | .map_err(|_| HgError::corrupted("Overflow in dirstate."))?; | |
|
88 | u8::slice_from_bytes(rest, filename_len) | |
|
89 | .map_err(|_| | |
|
90 | HgError::corrupted(format!( | |
|
91 | "dirstate corrupted: ran out of bytes at entry {}, offset {} (expected {} bytes).", | |
|
92 | entry_idx, original_len-contents.len(), filename_len)) | |
|
93 | )?; | |
|
80 | 94 | |
|
81 | 95 | // `paths` is either a single path, or two paths separated by a NULL |
|
82 | 96 | // byte |
@@ -87,6 +101,7 b" pub fn parse_dirstate_entries<'a>(" | |||
|
87 | 101 | let copy_source = iter.next().map(HgPath::new); |
|
88 | 102 | each_entry(path, &entry, copy_source)?; |
|
89 | 103 | |
|
104 | entry_idx += 1; | |
|
90 | 105 | contents = rest; |
|
91 | 106 | } |
|
92 | 107 | Ok(parents) |
General Comments 0
You need to be logged in to leave comments.
Login now