Skip to content

Commit

Permalink
Fix "source slice length does not match destination" panic on some tr…
Browse files Browse the repository at this point in the history
…acks

Fixes #1188

Co-authored-by: thedtvn <[email protected]>
  • Loading branch information
roderickvd and thedtvn committed Oct 27, 2024
1 parent cd57f70 commit f96f36c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
12 changes: 9 additions & 3 deletions core/src/file_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit f96f36c

Please sign in to comment.