diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-10-02 13:34:22 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-10-02 15:09:11 +0200 |
commit | 3b8046a1493755941f9ddb7f27ca0f6928919b1f (patch) | |
tree | 452696a3316e28d27c2182328d8d399eca801969 /openpgp/src/packet | |
parent | 02ed1941b9bac479603a6fd465644f528ba282a7 (diff) |
openpgp: Make SubpacketArea::new fallible.
- Fail if the given subpackets exceed the maximum size of a
subpacket area.
Diffstat (limited to 'openpgp/src/packet')
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index 65d0b815..5fff4d4d 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -524,13 +524,13 @@ impl_arbitrary_with_bound!(SubpacketArea); impl Default for SubpacketArea { fn default() -> Self { - Self::new(Default::default()) + Self::new(Default::default()).unwrap() } } impl Clone for SubpacketArea { fn clone(&self) -> Self { - Self::new(self.packets.clone()) + Self::new(self.packets.clone()).unwrap() } } @@ -581,10 +581,17 @@ impl<'a> IntoIterator for &'a SubpacketArea { impl SubpacketArea { /// Returns a new subpacket area containing the given `packets`. - pub fn new(packets: Vec<Subpacket>) -> SubpacketArea { - SubpacketArea { + pub fn new(packets: Vec<Subpacket>) -> Result<SubpacketArea> { + let area = SubpacketArea { packets, parsed: Mutex::new(RefCell::new(None)), + }; + if area.serialized_len() > std::u16::MAX as usize { + Err(Error::InvalidArgument( + format!("Subpacket area exceeds maximum size: {}", + area.serialized_len())).into()) + } else { + Ok(area) } } |