This leads to the first seemingly correct parsing of simple index files.
Unified · Split
| @@ -318,9 +318,9 @@ fn read_u16(data: &[u8]) -> Option<(u16, &[u8])> { · 317 unmodified lines | ||
| 318 | 318 | |
| 319 | 319 | fn load_extensions(beginning_of_extensions: &[u8], object_hash: git_hash::Kind) -> (Extensions, &[u8]) { |
| 320 | 320 | extension::Iter::new_without_checksum(beginning_of_extensions, object_hash) |
| 321 | − .map(|mut extensions| { | |
| 321 | + .map(|mut ext_iter| { | |
| 322 | 322 | let mut ext = Extensions::default(); |
| 323 | − for (signature, ext_data) in extensions.by_ref() { | |
| 323 | + for (signature, ext_data) in ext_iter.by_ref() { | |
| 324 | 324 | match signature { |
| 325 | 325 | extension::tree::SIGNATURE => { |
| 326 | 326 | ext.cache_tree = extension::tree::decode(ext_data, object_hash); |
| @@ -329,7 +329,7 @@ fn load_extensions(beginning_of_extensions: &[u8], object_hash: git_hash::Kind) · 2 unmodified lines | ||
| 329 | 329 | _unknown => {} // skip unknown extensions, too |
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | − (ext, extensions.data) | |
| 332 | + (ext, &beginning_of_extensions[ext_iter.consumed..]) | |
| 333 | 333 | }) |
| 334 | 334 | .unwrap_or_else(|| (Extensions::default(), beginning_of_extensions)) |
| 335 | 335 | } |
| @@ -81,6 +81,7 @@ mod iter { · 80 unmodified lines | ||
| 81 | 81 | pub fn new(data_at_beginning_of_extensions_and_truncated: &'a [u8]) -> Self { |
| 82 | 82 | Iter { |
| 83 | 83 | data: data_at_beginning_of_extensions_and_truncated, |
| 84 | + consumed: 0, | |
| 84 | 85 | } |
| 85 | 86 | } |
| 86 | 87 | |
| @@ -93,6 +94,7 @@ mod iter { · 6 unmodified lines | ||
| 93 | 94 | .checked_sub(object_hash.len_in_bytes())?; |
| 94 | 95 | Iter { |
| 95 | 96 | data: &data_at_beginning_of_extensions[..end], |
| 97 | + consumed: 0, | |
| 96 | 98 | } |
| 97 | 99 | .into() |
| 98 | 100 | } |
| @@ -108,11 +110,15 @@ mod iter { · 9 unmodified lines | ||
| 108 | 110 | |
| 109 | 111 | let (signature, data) = self.data.split_at(4); |
| 110 | 112 | let (size, data) = data.split_at(4); |
| 113 | + self.data = data; | |
| 114 | + self.consumed += 4 + 4; | |
| 115 | + | |
| 111 | 116 | let size = from_be_u32(size) as usize; |
| 112 | 117 | |
| 113 | 118 | match data.get(..size) { |
| 114 | 119 | Some(ext_data) => { |
| 115 | 120 | self.data = &data[size..]; |
| 121 | + self.consumed += size; | |
| 116 | 122 | Some((signature.try_into().unwrap(), ext_data)) |
| 117 | 123 | } |
| 118 | 124 | None => { |
| @@ -125,5 +131,6 @@ mod iter { · 6 unmodified lines | ||
| 125 | 131 | } |
| 126 | 132 | |
| 127 | 133 | pub struct Iter<'a> { |
| 128 | − pub data: &'a [u8], | |
| 134 | + data: &'a [u8], | |
| 135 | + pub consumed: usize, | |
| 129 | 136 | } |