Skip to content

Commit eaecf30

Browse files
Merge pull request #61 from TheBestTvarynka/fix/asn1-freezes-and-latency
Fix ASN1 freezes and latency on big input
2 parents 071d4d1 + 28570c4 commit eaecf30

20 files changed

+614
-64
lines changed

Cargo.lock

+124-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/asn1-parser/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ default-fearures = []
1313
std = []
1414

1515
[dev-dependencies]
16+
env_logger = "0.11.3"
1617
prop-strategies = { path = "../prop-strategies" }
1718
proptest = "1.2.0"
1819

@@ -22,3 +23,4 @@ num-bigint-dig = { version = "0.8.4", default-features = false }
2223
num-traits = { version = "0.2.17", default-features = false }
2324
oid = { version = "0.2.1", default-features = false }
2425
paste = "1.0.14"
26+
env_logger = "0.11.3"

crates/asn1-parser/src/asn1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl MetaInfo for Asn1Type<'_> {
212212
/// Information about raw data of the asn1 entity
213213
#[derive(Debug, Clone, PartialEq, Eq, Default)]
214214
pub struct RawAsn1EntityData<'data> {
215-
/// Raw input bytes for the current asn1 node
215+
/// Raw input bytes for the *current* asn1 node
216216
pub raw_data: Cow<'data, [u8]>,
217217

218218
/// Position of the tag in the input data

crates/asn1-parser/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ extern crate alloc;
55
#[macro_use]
66
mod macros;
77

8+
#[allow(unused_imports)]
9+
#[macro_use]
10+
extern crate log;
11+
812
mod asn1;
913
mod constructors;
1014
mod error;

crates/asn1-parser/src/time/utc_time.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ impl UtcTime {
3131
}
3232

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

crates/asn1-parser/tests/decode_encode.rs

+12
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,15 @@ fn decode_default() {
121121
let asn1 = Asn1::decode_buff(raw).unwrap();
122122
println!("{:?}", asn1);
123123
}
124+
125+
#[test]
126+
fn decode_utc() {
127+
std::env::set_var("RUST_LOG", "trace");
128+
env_logger::init();
129+
130+
let raw = &[23, 13, 49, 56, 48, 55, 49, 54, 49, 52, 53, 54, 51, 53, 90];
131+
let asn1 = Asn1::decode_buff(raw).unwrap();
132+
133+
let mut encoded = vec![0; asn1.needed_buf_size()];
134+
asn1.encode_buff(&mut encoded).expect("ASN1 encoding should not fail");
135+
}

src/asn1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pub fn asn1_parser_page() -> Html {
124124
error!("Can not decode asn1: {:?}", err);
125125
}
126126
}
127+
raw_asn1_setter.set(bytes);
127128
}
128129
}
129130
return;

0 commit comments

Comments
 (0)