diff --git a/CHANGELOG.md b/CHANGELOG.md index e585ea8b..dc6985b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- [core] Fix "source slice length (16) does not match destination slice length + (20)" panic on some tracks + ### Changed - [core] The `access_token` for http requests is now acquired by `login5` diff --git a/core/src/file_id.rs b/core/src/file_id.rs index 61b33125..ca23e84d 100644 --- a/core/src/file_id.rs +++ b/core/src/file_id.rs @@ -4,13 +4,19 @@ use librespot_protocol as protocol; use crate::{spotify_id::to_base16, Error}; +const RAW_LEN: usize = 20; + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct FileId(pub [u8; 20]); +pub struct FileId(pub [u8; RAW_LEN]); impl FileId { pub fn from_raw(src: &[u8]) -> FileId { - let mut dst = [0u8; 20]; - dst.clone_from_slice(src); + let mut dst = [0u8; RAW_LEN]; + let len = src.len(); + // some tracks return 16 instead of 20 bytes: #1188 + if len <= RAW_LEN { + dst[..len].clone_from_slice(src); + } FileId(dst) }