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

This commit is contained in:
= 2022-08-21 01:22:12 +02:00 committed by Mike Welsh
parent 55566037f7
commit 44cfaa9200
5 changed files with 12 additions and 22 deletions

View File

@ -861,7 +861,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
parent_data: &SwfSlice, parent_data: &SwfSlice,
) -> Result<FrameControl<'gc>, Error<'gc>> { ) -> Result<FrameControl<'gc>, Error<'gc>> {
let swf_version = self.swf_version(); let swf_version = self.swf_version();
let func_data = parent_data.to_unbounded_subslice(action.actions).unwrap(); let func_data = parent_data.to_unbounded_subslice(action.actions);
let constant_pool = self.constant_pool(); let constant_pool = self.constant_pool();
let func = Avm1Function::from_swf_function( let func = Avm1Function::from_swf_function(
self.context.gc_context, self.context.gc_context,
@ -2124,8 +2124,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
action: &Try, action: &Try,
parent_data: &SwfSlice, parent_data: &SwfSlice,
) -> Result<FrameControl<'gc>, Error<'gc>> { ) -> Result<FrameControl<'gc>, Error<'gc>> {
let mut result = let mut result = self.run_actions(parent_data.to_unbounded_subslice(action.try_body));
self.run_actions(parent_data.to_unbounded_subslice(action.try_body).unwrap());
if let Some((catch_vars, actions)) = &action.catch_body { if let Some((catch_vars, actions)) = &action.catch_body {
if let Err(Error::ThrownValue(value)) = &result { if let Err(Error::ThrownValue(value)) = &result {
@ -2151,14 +2150,13 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
} }
} }
result = result = activation.run_actions(parent_data.to_unbounded_subslice(actions));
activation.run_actions(parent_data.to_unbounded_subslice(actions).unwrap());
} }
} }
if let Some(actions) = action.finally_body { if let Some(actions) = action.finally_body {
if let ReturnType::Explicit(value) = if let ReturnType::Explicit(value) =
self.run_actions(parent_data.to_unbounded_subslice(actions).unwrap())? self.run_actions(parent_data.to_unbounded_subslice(actions))?
{ {
return Ok(FrameControl::Return(ReturnType::Explicit(value))); return Ok(FrameControl::Return(ReturnType::Explicit(value)));
} }
@ -2212,7 +2210,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
action: With, action: With,
parent_data: &SwfSlice, parent_data: &SwfSlice,
) -> Result<FrameControl<'gc>, Error<'gc>> { ) -> Result<FrameControl<'gc>, Error<'gc>> {
let code = parent_data.to_unbounded_subslice(action.actions).unwrap(); let code = parent_data.to_unbounded_subslice(action.actions);
let value = self.context.avm1.pop(); let value = self.context.avm1.pop();
match value { match value {
// Undefined/null with is ignored. // Undefined/null with is ignored.

View File

@ -46,9 +46,7 @@ impl<'gc> Avm1Button<'gc> {
) -> Self { ) -> Self {
let mut actions = vec![]; let mut actions = vec![];
for action in &button.actions { for action in &button.actions {
let action_data = source_movie let action_data = source_movie.to_unbounded_subslice(action.action_data);
.to_unbounded_subslice(action.action_data)
.unwrap();
let bits = action.conditions.bits(); let bits = action.conditions.bits();
let mut bit = 1u16; let mut bit = 1u16;
while bits & !(bit - 1) != 0 { while bits & !(bit - 1) != 0 {

View File

@ -3563,9 +3563,7 @@ impl ClipEventHandler {
} else { } else {
ButtonKeyCode::Unknown ButtonKeyCode::Unknown
}; };
let action_data = SwfSlice::from(movie) let action_data = SwfSlice::from(movie).to_unbounded_subslice(other.action_data);
.to_unbounded_subslice(other.action_data)
.unwrap();
Self { Self {
events: other.events, events: other.events,
key_code, key_code,

View File

@ -143,11 +143,7 @@ impl<'gc> Video<'gc> {
log::warn!("Duplicate frame {}", tag.frame_num); log::warn!("Duplicate frame {}", tag.frame_num);
} }
if let Some(subslice) = subslice { frames.insert(tag.frame_num.into(), (subslice.start, subslice.end));
frames.insert(tag.frame_num.into(), (subslice.start, subslice.end));
} else {
log::warn!("Invalid bitstream subslice on frame {}", tag.frame_num);
}
} }
} }
} }

View File

@ -224,19 +224,19 @@ impl SwfSlice {
/// ///
/// This function allows subslices outside the current slice to be formed, /// This function allows subslices outside the current slice to be formed,
/// as long as they are valid subslices of the movie itself. /// as long as they are valid subslices of the movie itself.
pub fn to_unbounded_subslice(&self, slice: &[u8]) -> Option<Self> { pub fn to_unbounded_subslice(&self, slice: &[u8]) -> Self {
let self_pval = self.movie.data().as_ptr() as usize; let self_pval = self.movie.data().as_ptr() as usize;
let self_len = self.movie.data().len(); let self_len = self.movie.data().len();
let slice_pval = slice.as_ptr() as usize; let slice_pval = slice.as_ptr() as usize;
if self_pval <= slice_pval && slice_pval < (self_pval + self_len) { if self_pval <= slice_pval && slice_pval < (self_pval + self_len) {
Some(Self { Self {
movie: self.movie.clone(), movie: self.movie.clone(),
start: slice_pval - self_pval, start: slice_pval - self_pval,
end: (slice_pval - self_pval) + slice.len(), end: (slice_pval - self_pval) + slice.len(),
}) }
} else { } else {
None self.copy_empty()
} }
} }