Skip to content

Panic when parsing malformed signature #146

@ghost

Description

Reproduction code:

use pgp::de::Deserialize;

fn main() {
    let data = [5, 2, 2, 11, 0, 2, 0, 0];
    let _ = pgp::Signature::from_slice(pgp::types::Version::New, &data);
}

Error:

thread 'main' panicked at 'attempt to subtract with overflow', /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/pgp-0.7.2/src/packet/signature/de.rs:316:29
stack backtrace:
   0: rust_begin_unwind
             at /rustc/891ca5f63c3b3cfe3939710a728671243e881ed6/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/891ca5f63c3b3cfe3939710a728671243e881ed6/library/core/src/panicking.rs:106:14
   2: core::panicking::panic
             at /rustc/891ca5f63c3b3cfe3939710a728671243e881ed6/library/core/src/panicking.rs:47:5
   3: pgp::packet::signature::de::subpackets
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/pgp-0.7.2/src/packet/signature/de.rs:316:29
   4: pgp::packet::signature::de::v4_parser::{{closure}}
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-4.2.3/src/simple_errors.rs:195:15
   5: core::result::Result<T,E>::and_then
             at /rustc/891ca5f63c3b3cfe3939710a728671243e881ed6/library/core/src/result.rs:966:22
   6: pgp::packet::signature::de::v4_parser
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-4.2.3/src/macros.rs:239:13
   7: pgp::packet::signature::de::parse
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-4.2.3/src/macros.rs:239:13
   8: pgp::packet::signature::de::<impl pgp::de::Deserialize for pgp::packet::signature::types::Signature>::from_slice
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/pgp-0.7.2/src/packet/signature/de.rs:25:23
   9: scratchbZarvjayp::main
             at ./src/main.rs:5:13
  10: core::ops::function::FnOnce::call_once
             at /rustc/891ca5f63c3b3cfe3939710a728671243e881ed6/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions