swf: Don't error on focal gradients in DefineShape tags (fix #2730)

This commit is contained in:
Mike Welsh 2021-01-21 14:53:54 -08:00
parent ab92bc1b98
commit 2254589e71
2 changed files with 14 additions and 43 deletions

View File

@ -1369,7 +1369,7 @@ impl<'a> Reader<'a> {
let mut start_fill_styles = Vec::with_capacity(num_fill_styles);
let mut end_fill_styles = Vec::with_capacity(num_fill_styles);
for _ in 0..num_fill_styles {
let (start, end) = self.read_morph_fill_style(shape_version)?;
let (start, end) = self.read_morph_fill_style()?;
start_fill_styles.push(start);
end_fill_styles.push(end);
}
@ -1495,7 +1495,7 @@ impl<'a> Reader<'a> {
)
};
let (start_fill_style, end_fill_style) = if has_fill {
let (start, end) = self.read_morph_fill_style(shape_version)?;
let (start, end) = self.read_morph_fill_style()?;
(Some(start), Some(end))
} else {
(None, None)
@ -1529,7 +1529,7 @@ impl<'a> Reader<'a> {
}
}
fn read_morph_fill_style(&mut self, shape_version: u8) -> Result<(FillStyle, FillStyle)> {
fn read_morph_fill_style(&mut self) -> Result<(FillStyle, FillStyle)> {
let fill_style_type = self.read_u8()?;
let fill_style = match fill_style_type {
0x00 => {
@ -1555,12 +1555,8 @@ impl<'a> Reader<'a> {
}
0x13 => {
if self.version < 8 || shape_version < 2 {
return Err(Error::invalid_data(
"Focal gradients are only supported in SWF version 8 \
or higher.",
));
}
// SWF19 says focal gradients are only allowed in SWFv8+ and DefineMorphShapeShape2,
// but it works even in earlier tags (#2730).
// TODO(Herschel): How is focal_point stored?
let (start_gradient, end_gradient) = self.read_morph_gradient()?;
let start_focal_point = self.read_fixed8()?;
@ -1755,18 +1751,12 @@ impl<'a> Reader<'a> {
0x12 => FillStyle::RadialGradient(self.read_gradient(shape_version)?),
0x13 => {
if self.version < 8 || shape_version < 4 {
return Err(Error::invalid_data(
"Focal gradients are only supported in SWF version 8 \
or higher.",
));
}
FillStyle::FocalGradient {
0x13 => FillStyle::FocalGradient {
// SWF19 says focal gradients are only allowed in SWFv8+ and DefineShape4,
// but it works even in earlier tags (#2730).
gradient: self.read_gradient(shape_version)?,
focal_point: self.read_fixed8()?,
}
}
},
0x40..=0x43 => FillStyle::Bitmap {
id: self.read_u16()?,

View File

@ -1179,7 +1179,7 @@ impl<W: Write> Writer<W> {
.iter()
.zip(data.end.fill_styles.iter())
{
writer.write_morph_fill_style(start, end, data.version)?;
writer.write_morph_fill_style(start, end)?;
}
if num_line_styles >= 0xff {
@ -1263,12 +1263,7 @@ impl<W: Write> Writer<W> {
Ok(())
}
fn write_morph_fill_style(
&mut self,
start: &FillStyle,
end: &FillStyle,
shape_version: u8,
) -> Result<()> {
fn write_morph_fill_style(&mut self, start: &FillStyle, end: &FillStyle) -> Result<()> {
match (start, end) {
(&FillStyle::Color(ref start_color), &FillStyle::Color(ref end_color)) => {
self.write_u8(0x00)?; // Solid color.
@ -1302,13 +1297,6 @@ impl<W: Write> Writer<W> {
focal_point: end_focal_point,
},
) => {
if self.version < 8 || shape_version < 2 {
return Err(Error::invalid_data(
"Focal gradients are only support in SWF version 8 \
and higher.",
));
}
self.write_u8(0x13)?; // Focal gradient.
self.write_morph_gradient(start_gradient, end_gradient)?;
self.write_fixed8(start_focal_point)?;
@ -1443,7 +1431,7 @@ impl<W: Write> Writer<W> {
}
(&Some(ref start_fill), &Some(ref end_fill)) => {
self.write_morph_fill_style(start_fill, end_fill, shape_version)?
self.write_morph_fill_style(start_fill, end_fill)?
}
_ => {
@ -1772,13 +1760,6 @@ impl<W: Write> Writer<W> {
ref gradient,
focal_point,
} => {
if self.version < 8 {
return Err(Error::invalid_data(
"Focal gradients are only support in SWF version 8 \
and higher.",
));
}
self.write_u8(0x13)?; // Focal gradient.
self.write_gradient(gradient, shape_version)?;
self.write_fixed8(focal_point)?;