Fix "source slice length does not match destination" panic on some tracks

Fixes #1188

Co-authored-by: thedtvn <duongtuan30306@gmail.com>
This commit is contained in:
Roderick van Domburg 2024-10-27 15:59:25 +01:00
parent cd57f706f6
commit f96f36c064
No known key found for this signature in database
GPG key ID: FE2585E713F9F30A
2 changed files with 14 additions and 3 deletions

View file

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Fixed
- [core] Fix "source slice length (16) does not match destination slice length
(20)" panic on some tracks
### Changed ### Changed
- [core] The `access_token` for http requests is now acquired by `login5` - [core] The `access_token` for http requests is now acquired by `login5`

View file

@ -4,13 +4,19 @@ use librespot_protocol as protocol;
use crate::{spotify_id::to_base16, Error}; use crate::{spotify_id::to_base16, Error};
const RAW_LEN: usize = 20;
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FileId(pub [u8; 20]); pub struct FileId(pub [u8; RAW_LEN]);
impl FileId { impl FileId {
pub fn from_raw(src: &[u8]) -> FileId { pub fn from_raw(src: &[u8]) -> FileId {
let mut dst = [0u8; 20]; let mut dst = [0u8; RAW_LEN];
dst.clone_from_slice(src); 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) FileId(dst)
} }