mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
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:
parent
cd57f706f6
commit
f96f36c064
2 changed files with 14 additions and 3 deletions
|
@ -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`
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue