mirror of
https://github.com/storytold/deckcraft.git
synced 2026-10-24 18:46:57 -06:00
security: clamp alpha_num bullet expansion and sanitize filename logging (#1264)
This commit is contained in:
@@ -41,8 +41,9 @@ pub fn poll(inbox: &Inbox, app: &mut SlideApp, ctx: &egui::Context) {
|
||||
Event::Open(paths) => {
|
||||
for p in paths.iter().filter_map(|p| p.to_str()) {
|
||||
if let Err(e) = app.open_path(p) {
|
||||
log::error!("{p}: {e}");
|
||||
app.set_status(format!("Couldn't open {p}: {e}"));
|
||||
let safe_p = p.replace(['\r', '\n'], " ");
|
||||
log::error!("{safe_p}: {e}");
|
||||
app.set_status(format!("Couldn't open {safe_p}: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,11 +572,10 @@ fn alpha_num(n: u32, upper: bool) -> String {
|
||||
if n == 0 {
|
||||
return String::new();
|
||||
}
|
||||
let mut n = n - 1;
|
||||
let n = n - 1;
|
||||
let c = (b'a' + (n % 26) as u8) as char;
|
||||
let reps = n / 26 + 1;
|
||||
n = reps;
|
||||
let s: String = std::iter::repeat_n(c, n as usize).collect();
|
||||
let reps = (n / 26 + 1).min(50);
|
||||
let s: String = std::iter::repeat_n(c, reps as usize).collect();
|
||||
if upper { s.to_uppercase() } else { s }
|
||||
}
|
||||
|
||||
|
||||
@@ -394,6 +394,7 @@ fn autonum_formats() {
|
||||
assert_eq!(autonum("alphaLcParenR", 2), "b)");
|
||||
assert_eq!(autonum("arabicParenBoth", 1), "(1)");
|
||||
assert_eq!(autonum("alphaUcPeriod", 27), "AA.");
|
||||
assert_eq!(autonum("alphaUcPeriod", u32::MAX).len(), 51); // 50 letters + '.'
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user