make the buffer slicing checked instead of assumed
This commit is contained in:
@@ -377,7 +377,9 @@ fn adjust_audio_length(path: &Path, sample_rate: u32, channels: u16, target_secs
|
||||
while remaining > 0 {
|
||||
// zeros.len() is 64KiB, so both directions are lossless here.
|
||||
let chunk = u64::try_from(zeros.len()).unwrap_or(u64::MAX);
|
||||
let to_write = usize::try_from(remaining.min(chunk)).unwrap_or(zeros.len());
|
||||
let to_write = usize::try_from(remaining.min(chunk))
|
||||
.unwrap_or(zeros.len())
|
||||
.min(zeros.len());
|
||||
file.write_all(&zeros[..to_write])?;
|
||||
remaining -= u64::try_from(to_write).unwrap_or(0);
|
||||
}
|
||||
@@ -412,7 +414,9 @@ fn pad_audio_head(path: &Path, sample_rate: u32, channels: u16, head_secs: f64)
|
||||
while remaining > 0 {
|
||||
// zeros.len() is 64KiB, so both directions are lossless here.
|
||||
let chunk = u64::try_from(zeros.len()).unwrap_or(u64::MAX);
|
||||
let to_write = usize::try_from(remaining.min(chunk)).unwrap_or(zeros.len());
|
||||
let to_write = usize::try_from(remaining.min(chunk))
|
||||
.unwrap_or(zeros.len())
|
||||
.min(zeros.len());
|
||||
out.write_all(&zeros[..to_write])?;
|
||||
remaining -= u64::try_from(to_write).unwrap_or(0);
|
||||
}
|
||||
@@ -1794,8 +1798,10 @@ fn read_log_tail(log_dir: &Path) -> String {
|
||||
}
|
||||
let Some((_, path)) = newest else { return String::new() };
|
||||
let Ok(data) = std::fs::read(&path) else { return String::new() };
|
||||
// saturating_sub keeps start at or below data.len(), so the tail slice
|
||||
// always exists; get() just makes that explicit.
|
||||
let start = data.len().saturating_sub(TAIL_BYTES);
|
||||
String::from_utf8_lossy(&data[start..]).into_owned()
|
||||
String::from_utf8_lossy(data.get(start..).unwrap_or_default()).into_owned()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
Reference in New Issue
Block a user