Skip to content

Commit 4838e5f

Browse files
committed
Fixed panic parsing broken HTMLs
1 parent 6bb468c commit 4838e5f

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ members = [
2323
[profile.dev]
2424
opt-level = 0
2525
debug = 1
26-
codegen-units = 4
26+
#codegen-units = 4
2727
lto = false
2828
incremental = true
2929
panic = 'unwind'

crates/smtp/src/queue/manager.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,16 @@ impl Queue {
144144
Total = queue_events.len(),
145145
Details = self
146146
.on_hold
147-
.keys()
148-
.copied()
147+
.values()
148+
.fold([0, 0, 0], |mut acc, v| {
149+
match v {
150+
OnHold::InFlight => acc[0] += 1,
151+
OnHold::ConcurrencyLimited { .. } => acc[1] += 1,
152+
OnHold::Locked { .. } => acc[2] += 1,
153+
}
154+
acc
155+
})
156+
.into_iter()
149157
.map(trc::Value::from)
150158
.collect::<Vec<_>>(),
151159
Limit = max_in_flight,
@@ -176,7 +184,20 @@ impl Queue {
176184
Queue(trc::QueueEvent::BackPressure),
177185
Reason = "Queue outbound processing capacity for this node exceeded.",
178186
Total = queue_events.len(),
179-
Details = self.on_hold.keys().copied().map(trc::Value::from).collect::<Vec<_>>(),
187+
Details = self
188+
.on_hold
189+
.values()
190+
.fold([0, 0, 0], |mut acc, v| {
191+
match v {
192+
OnHold::InFlight => acc[0] += 1,
193+
OnHold::ConcurrencyLimited { .. } => acc[1] += 1,
194+
OnHold::Locked { .. } => acc[2] += 1,
195+
}
196+
acc
197+
})
198+
.into_iter()
199+
.map(trc::Value::from)
200+
.collect::<Vec<_>>(),
180201
Limit = max_in_flight,
181202
);
182203
}

crates/spam-filter/src/modules/html.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
55
*/
66

7-
use mail_parser::decoders::html::add_html_token;
7+
use mail_parser::decoders::html::add_html_token;
88

99
#[derive(Debug, Eq, PartialEq, Clone)]
1010
pub enum HtmlToken {
@@ -201,10 +201,14 @@ pub fn html_to_tokens(input: &str) -> Vec<HtmlToken> {
201201
match ch {
202202
b'>' if !in_quote => {
203203
if !value.is_empty() {
204-
attributes.last_mut().unwrap().1 =
205-
String::from_utf8(value)
206-
.unwrap_or_default()
207-
.into();
204+
let value =
205+
String::from_utf8(value).unwrap_or_default();
206+
if let Some((_, v)) = attributes.last_mut() {
207+
*v = value.into();
208+
} else {
209+
// Broken attribute
210+
attributes.push((0, Some(value)));
211+
}
208212
}
209213
break 'outer;
210214
}
@@ -226,8 +230,13 @@ pub fn html_to_tokens(input: &str) -> Vec<HtmlToken> {
226230
}
227231

228232
if !value.is_empty() {
229-
attributes.last_mut().unwrap().1 =
230-
String::from_utf8(value).unwrap_or_default().into();
233+
let value = String::from_utf8(value).unwrap_or_default();
234+
if let Some((_, v)) = attributes.last_mut() {
235+
*v = value.into();
236+
} else {
237+
// Broken attribute
238+
attributes.push((0, Some(value)));
239+
}
231240
}
232241
}
233242
b' ' | b'\t' | b'\r' | b'\n' => {

0 commit comments

Comments
 (0)