core: Made SwfSlice::to_subslice return an empty slice in case of errors

This commit is contained in:
= 2022-08-21 01:23:20 +02:00 committed by Mike Welsh
parent 44cfaa9200
commit 3a1947445e
3 changed files with 6 additions and 7 deletions

View File

@ -306,7 +306,7 @@ impl Iterator for StreamTagReader {
self.mp3_samples_buffered += i32::from(num_samples);
audio_block = &audio_block[4..];
}
*audio_data = swf_data.to_subslice(audio_block).unwrap();
*audio_data = swf_data.to_subslice(audio_block);
Ok(())
}
TagCode::ShowFrame if compression == AudioCompression::Mp3 => {

View File

@ -5,6 +5,6 @@ pub type BinaryData = SwfSlice;
impl BinaryData {
pub fn from_swf_tag(movie: Arc<SwfMovie>, tag: &swf::DefineBinaryData) -> Self {
SwfSlice::from(movie).to_subslice(tag.data).unwrap()
SwfSlice::from(movie).to_subslice(tag.data)
}
}

View File

@ -205,18 +205,18 @@ impl SwfSlice {
///
/// This function returns None if the given slice is not a subslice of the
/// current slice.
pub fn to_subslice(&self, slice: &[u8]) -> Option<Self> {
pub fn to_subslice(&self, slice: &[u8]) -> Self {
let self_pval = self.movie.data().as_ptr() as usize;
let slice_pval = slice.as_ptr() as usize;
if (self_pval + self.start) <= slice_pval && slice_pval < (self_pval + self.end) {
Some(Self {
Self {
movie: self.movie.clone(),
start: slice_pval - self_pval,
end: (slice_pval - self_pval) + slice.len(),
})
}
} else {
None
self.copy_empty()
}
}
@ -289,7 +289,6 @@ impl SwfSlice {
if new_start <= new_end {
if let Some(result) = self.movie.data().get(new_start..new_end) {
self.to_subslice(result)
.unwrap_or_else(|| self.copy_empty())
} else {
self.copy_empty()
}