RazrFalcon / resvg

An SVG rendering library.
Mozilla Public License 2.0
2.61k stars 215 forks source link

Strange bug with pyo3 on macos #753

Closed baseplate-admin closed 1 month ago

baseplate-admin commented 2 months ago

Hi i have this following code

rust:

    let svg_string: String;

    if std::path::Path::new(&svg).exists() {
        let mut svg_data = std::fs::read(svg)
            .map_err(|_| "failed to open the provided file")
            .unwrap();
        if svg_data.starts_with(&[0x1f, 0x8b]) {
            svg_data = resvg::usvg::decompress_svgz(&svg_data)
                .map_err(|e| e.to_string())
                .unwrap();
        };
        svg_string = std::str::from_utf8(&svg_data).unwrap().to_owned();
    } else {
        svg_string = svg;
    }

python:

def test_path():
    path = os.path.join(BASE_DIR, "acid.svg")
    base = resvg_py.svg_to_base64()
    print(path)
    assert base == svg_output

def test_gzip_path():
    path = os.path.join(BASE_DIR, "acid.svg.gz")
    base = resvg_py.svg_to_base64()
    print(path)

    assert base == svg_output

This fails in macos but runs in all other OS.

Here is the log : https://github.com/baseplate-admin/resvg-py/actions/runs/8889901090/job/24409004312 Relevant Source :

LaurenzV commented 2 months ago

I don't really get it, can you provide a simple Rust code snippet and an SVG that when run allows us to reproduce it on the Rust side?

If that issue only happens with Python then there isn't much we can do here, I think, since resvg-py is an unaffiliated project.

baseplate-admin commented 2 months ago

I don't really get it, can you provide a simple Rust code snippet and an SVG that when run allows us to reproduce it on the Rust side?

the issue is on rust side, resvg fails to parse the svg only in mac, but works fine in windows/linux. That's what is bothering me.

But i will try to do a minimal reproduction of this issue. It is near impossible for me as i dont have access to a macbook

RazrFalcon commented 2 months ago

Can you provide/print that acid.svg. It seems like the string you're trying to parse is messed up somewhere on your side.

baseplate-admin commented 2 months ago

Can you provide/print that acid.svg.

Sure thing : https://github.com/baseplate-admin/resvg-py/blob/34c7e6065edead9f8e7aaa97341615db8b78677a/tests/acid.svg

It seems like the string you're trying to parse is messed up somewhere on your side.

I am really at a loss here, i dont have any way of testing on macos and it's not reproducible in my environment. Could you please tell me if i can help you in any way from windows/linux?

RazrFalcon commented 2 months ago

I do use macos, so if you can tell me how to run it locally - I will try.

baseplate-admin commented 2 months ago

I do use macos, so if you can tell me how to run it locally - I will try.

These are the steps i took on linux to get this repository running

First install python

  1. pip install pipx
  2. pipx install maturin poetry
  3. git clone https://github.com/baseplate-admin/resvg-py
  4. poetry install
  5. poetry shell
  6. maturin develop
  7. pytest .
baseplate-admin commented 1 month ago

Hi @RazrFalcon,

Sorry for bothering you with this issue.

Turns out this is a bug with python on macos..

Thank you all for helping me initially

LaurenzV commented 1 month ago

What's the bug? Out of curiosity.

baseplate-admin commented 1 month ago

The problem is with pip preferring PYPI over local package in macos. So essentially what i wrote in current package, even if i bumped the version would not be used.

Initial findings by this comment:

Which led me to this issue with pip:

References :

RazrFalcon commented 1 month ago

Good. No problem.