From f82c98a12ea1f6b4b9b3565656db00a1f69276d4 Mon Sep 17 00:00:00 2001 From: Polochon_street Date: Wed, 27 Dec 2023 12:58:28 +0100 Subject: [PATCH] Fix utf8 panic in the library module --- CHANGELOG.md | 3 ++- Cargo.lock | 2 +- Cargo.toml | 6 +++--- src/library.rs | 44 ++++++++++++++++++++++++++++++++++++++------ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85e64d2..a7f46d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ ## bliss 0.6.10 * Make the `analyze` function public, for people who don't want to use ffmpeg -* Run `cargo update` +* Run `cargo update`, bump ffmpeg to 6.1 +* Fix the library module erroring when wrong UTF-8 ends up in the database. ## bliss 0.6.9 * Add a feature flag for compilation on raspberry pis. diff --git a/Cargo.lock b/Cargo.lock index 361356c..0a0aea7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,7 +112,7 @@ checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "bliss-audio" -version = "0.6.9" +version = "0.6.10" dependencies = [ "anyhow", "bliss-audio-aubio-rs", diff --git a/Cargo.toml b/Cargo.toml index c19ff84..3540ae1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bliss-audio" -version = "0.6.9" +version = "0.6.10" build = "build.rs" authors = ["Polochon-street "] edition = "2021" @@ -40,8 +40,8 @@ serde = ["dep:serde"] # Hopefully we'll be able to use the official aubio-rs at some point. bliss-audio-aubio-rs = "0.2.1" crossbeam = "0.8.2" -ffmpeg-next = "6.0.0" -ffmpeg-sys-next = { version = "6.0.1", default-features = false } +ffmpeg-next = "6.1.0" +ffmpeg-sys-next = { version = "6.1.0", default-features = false } log = "0.4.17" ndarray = { version = "0.15.6", features = ["rayon"] } num_cpus = "1.15.0" diff --git a/src/library.rs b/src/library.rs index a0d3b5d..e227b62 100644 --- a/src/library.rs +++ b/src/library.rs @@ -1081,12 +1081,42 @@ impl Library { let song = Song { path: PathBuf::from(path), - artist: row.get(1).unwrap(), - title: row.get(2).unwrap(), - album: row.get(3).unwrap(), - album_artist: row.get(4).unwrap(), - track_number: row.get(5).unwrap(), - genre: row.get(6).unwrap(), + artist: row + .get_ref(1) + .unwrap() + .as_bytes_or_null() + .unwrap() + .map(|v| String::from_utf8_lossy(v).to_string()), + title: row + .get_ref(2) + .unwrap() + .as_bytes_or_null() + .unwrap() + .map(|v| String::from_utf8_lossy(v).to_string()), + album: row + .get_ref(3) + .unwrap() + .as_bytes_or_null() + .unwrap() + .map(|v| String::from_utf8_lossy(v).to_string()), + album_artist: row + .get_ref(4) + .unwrap() + .as_bytes_or_null() + .unwrap() + .map(|v| String::from_utf8_lossy(v).to_string()), + track_number: row + .get_ref(5) + .unwrap() + .as_bytes_or_null() + .unwrap() + .map(|v| String::from_utf8_lossy(v).to_string()), + genre: row + .get_ref(6) + .unwrap() + .as_bytes_or_null() + .unwrap() + .map(|v| String::from_utf8_lossy(v).to_string()), analysis: Analysis { internal_analysis: [0.; NUMBER_FEATURES], }, @@ -1287,6 +1317,8 @@ fn data_local_dir() -> Option { #[cfg(test)] // TODO refactor (especially the helper functions) +// TODO the tests should really open a songs.db +// TODO test with invalid UTF-8 mod test { use super::*; use crate::{Analysis, NUMBER_FEATURES};