Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix ASN1 freezes and latency on big input #61

Merged
merged 5 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 124 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/asn1-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ default-fearures = []
std = []

[dev-dependencies]
env_logger = "0.11.3"
prop-strategies = { path = "../prop-strategies" }
proptest = "1.2.0"

Expand All @@ -22,3 +23,4 @@ num-bigint-dig = { version = "0.8.4", default-features = false }
num-traits = { version = "0.2.17", default-features = false }
oid = { version = "0.2.1", default-features = false }
paste = "1.0.14"
env_logger = "0.11.3"
2 changes: 1 addition & 1 deletion crates/asn1-parser/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl MetaInfo for Asn1Type<'_> {
/// Information about raw data of the asn1 entity
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct RawAsn1EntityData<'data> {
/// Raw input bytes for the current asn1 node
/// Raw input bytes for the *current* asn1 node
pub raw_data: Cow<'data, [u8]>,

/// Position of the tag in the input data
Expand Down
4 changes: 4 additions & 0 deletions crates/asn1-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ extern crate alloc;
#[macro_use]
mod macros;

#[allow(unused_imports)]
#[macro_use]
extern crate log;

mod asn1;
mod constructors;
mod error;
Expand Down
3 changes: 2 additions & 1 deletion crates/asn1-parser/src/time/utc_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ impl UtcTime {
}

fn calc_data_len(&self) -> usize {
2 /* year */ + 2 /* month */ + 2 /* day */ + 2 /* hour */ + 2 /* minute */ + self.second.is_some().then_some(2).unwrap_or_default()
2 /* year */ + 2 /* month */ + 2 /* day */ + 2 /* hour */ + 2 /* minute */ + self.second.is_some().then_some(2).unwrap_or_default() + 1
/* 'Z' */
}
}

Expand Down
12 changes: 12 additions & 0 deletions crates/asn1-parser/tests/decode_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,15 @@ fn decode_default() {
let asn1 = Asn1::decode_buff(raw).unwrap();
println!("{:?}", asn1);
}

#[test]
fn decode_utc() {
std::env::set_var("RUST_LOG", "trace");
env_logger::init();

let raw = &[23, 13, 49, 56, 48, 55, 49, 54, 49, 52, 53, 54, 51, 53, 90];
let asn1 = Asn1::decode_buff(raw).unwrap();

let mut encoded = vec![0; asn1.needed_buf_size()];
asn1.encode_buff(&mut encoded).expect("ASN1 encoding should not fail");
}
1 change: 1 addition & 0 deletions src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub fn asn1_parser_page() -> Html {
error!("Can not decode asn1: {:?}", err);
}
}
raw_asn1_setter.set(bytes);
}
}
return;
Expand Down
Loading