Skip to content

Commit f96f36c

Browse files
roderickvdthedtvn
andcommitted
Fix "source slice length does not match destination" panic on some tracks
Fixes #1188 Co-authored-by: thedtvn <[email protected]>
1 parent cd57f70 commit f96f36c

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- [core] Fix "source slice length (16) does not match destination slice length
13+
(20)" panic on some tracks
14+
1015
### Changed
1116

1217
- [core] The `access_token` for http requests is now acquired by `login5`

core/src/file_id.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ use librespot_protocol as protocol;
44

55
use crate::{spotify_id::to_base16, Error};
66

7+
const RAW_LEN: usize = 20;
8+
79
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
8-
pub struct FileId(pub [u8; 20]);
10+
pub struct FileId(pub [u8; RAW_LEN]);
911

1012
impl FileId {
1113
pub fn from_raw(src: &[u8]) -> FileId {
12-
let mut dst = [0u8; 20];
13-
dst.clone_from_slice(src);
14+
let mut dst = [0u8; RAW_LEN];
15+
let len = src.len();
16+
// some tracks return 16 instead of 20 bytes: #1188
17+
if len <= RAW_LEN {
18+
dst[..len].clone_from_slice(src);
19+
}
1420
FileId(dst)
1521
}
1622

0 commit comments

Comments
 (0)