Skip to content

Commit

Permalink
Use 'flate2' instead of 'libflate' for GZip decoding.
Browse files Browse the repository at this point in the history
Closes #143
  • Loading branch information
RazrFalcon committed Sep 14, 2019
1 parent 92c499e commit 6f7b204
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This changelog also contains important changes in dependencies.
### Changed
- Allow `feComposite` k1-4 coefficients to be larger than 1.0
This matches browsers behaviour.
- Use `flate2` instead of `libflate` for GZip decoding.

### Fixed
- `feComposite` with fully transparent regions was producing invalid results.
Expand Down
46 changes: 21 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion usvg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ travis-ci = { repository = "RazrFalcon/resvg" }
[dependencies]
base64 = "0.10"
data-url = "0.1"
flate2 = { version = "1.0.11", default-features = false, features = ["rust_backend"]}
kurbo = "0.2.3"
libflate = "0.1.25"
log = "0.4"
rctree = "0.3"
xmlwriter = "0.1"
Expand Down
15 changes: 9 additions & 6 deletions usvg/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Tree {
/// Can contain an SVG string or a gzip compressed data.
pub fn from_data(data: &[u8], opt: &Options) -> Result<Self, Error> {
if data.starts_with(&[0x1f, 0x8b]) {
let text = deflate(data, data.len())?;
let text = deflate(data)?;
Self::from_str(&text, opt)
} else {
let text = ::std::str::from_utf8(data).map_err(|_| Error::NotAnUtf8Str)?;
Expand Down Expand Up @@ -256,7 +256,9 @@ pub fn load_svg_file(path: &path::Path) -> Result<String, Error> {

match ext.as_str() {
"svgz" => {
deflate(&file, length)
let mut data = Vec::with_capacity(length);
file.read_to_end(&mut data).map_err(|_| Error::FileOpenFailed)?;
deflate(&data)
}
"svg" => {
let mut s = String::with_capacity(length);
Expand All @@ -269,12 +271,13 @@ pub fn load_svg_file(path: &path::Path) -> Result<String, Error> {
}
}

fn deflate<R: ::std::io::Read>(inner: R, len: usize) -> Result<String, Error> {
fn deflate(data: &[u8]) -> Result<String, Error> {
use std::io::Read;

let mut decoder = libflate::gzip::Decoder::new(inner).map_err(|_| Error::MalformedGZip)?;
let mut decoded = String::with_capacity(len * 2);
decoder.read_to_string(&mut decoded).map_err(|_| Error::NotAnUtf8Str)?;
let mut decoder = flate2::read::GzDecoder::new(data);
let mut decoded = Vec::with_capacity(data.len() * 2);
decoder.read_to_end(&mut decoded).map_err(|_| Error::MalformedGZip)?;
let decoded = String::from_utf8(decoded).map_err(|_| Error::NotAnUtf8Str)?;
Ok(decoded)
}

Expand Down

0 comments on commit 6f7b204

Please sign in to comment.