Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange bug with pyo3 on macos #753

Closed
baseplate-admin opened this issue Apr 30, 2024 · 10 comments
Closed

Strange bug with pyo3 on macos #753

baseplate-admin opened this issue Apr 30, 2024 · 10 comments

Comments

@baseplate-admin
Copy link

baseplate-admin commented Apr 30, 2024

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 :

@baseplate-admin baseplate-admin changed the title Strange bug on macos Strange bug with pyo3 on macos Apr 30, 2024
@LaurenzV
Copy link
Contributor

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
Copy link
Author

baseplate-admin commented Apr 30, 2024

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
Copy link
Collaborator

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
Copy link
Author

baseplate-admin commented Apr 30, 2024

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
Copy link
Collaborator

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

@baseplate-admin
Copy link
Author

baseplate-admin commented Apr 30, 2024

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
Copy link
Author

baseplate-admin commented May 6, 2024

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

@baseplate-admin baseplate-admin closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
@LaurenzV
Copy link
Contributor

LaurenzV commented May 6, 2024

What's the bug? Out of curiosity.

@baseplate-admin
Copy link
Author

@RazrFalcon
Copy link
Collaborator

Good. No problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants