Fix potential unsoundness in SqliteMallocString

This commit is contained in:
Thom Chiovoloni 2022-09-16 13:29:37 -07:00
parent 5a41ab869a
commit a100adc1f2

View File

@ -131,7 +131,8 @@ impl SqliteMallocString {
// (everything is aligned to 1) // (everything is aligned to 1)
// - `size` is also never zero, although this function doesn't actually require // - `size` is also never zero, although this function doesn't actually require
// it now. // it now.
let layout = Layout::from_size_align_unchecked(s.len().saturating_add(1), 1); let len = s.len().saturating_add(1).min(isize::MAX as usize);
let layout = Layout::from_size_align_unchecked(len, 1);
// Note: This call does not return. // Note: This call does not return.
handle_alloc_error(layout); handle_alloc_error(layout);
}); });