Mercurial > hg
diff rust/hg-core/src/dirstate_tree/dirstate_map.rs @ 47675:48aec076b8fb
dirstate-v2: Enforce data size read from the docket file
The data file may not be shorter than its size given by the docket.
It may be longer, but additional data is ignored.
Differential Revision: https://phab.mercurial-scm.org/D11089
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 12 Jul 2021 22:46:52 +0200 |
parents | ff97e793ed36 |
children | 065e61628980 |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs Thu Jul 08 12:18:21 2021 +0200 +++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs Mon Jul 12 22:46:52 2021 +0200 @@ -410,8 +410,15 @@ } #[timed] - pub fn new_v2(on_disk: &'on_disk [u8]) -> Result<Self, DirstateError> { - Ok(on_disk::read(on_disk)?) + pub fn new_v2( + on_disk: &'on_disk [u8], + data_size: usize, + ) -> Result<Self, DirstateError> { + if let Some(data) = on_disk.get(..data_size) { + Ok(on_disk::read(data)?) + } else { + Err(DirstateV2ParseError.into()) + } } #[timed]