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

[python] Panic on Python 3.12 #439

Closed
aMarcireau opened this issue Nov 6, 2023 · 4 comments · Fixed by #464
Closed

[python] Panic on Python 3.12 #439

aMarcireau opened this issue Nov 6, 2023 · 4 comments · Fixed by #464

Comments

@aMarcireau
Copy link

jsonschema_rs.JSONSchema with Python 3.12 crashes the interpreter when parsing schemas with strings that contain 113 characters or more.

Steps to reproduce (works on Python < 3.12 but crashes on 3.12).

import jsonschema_rs

jsonschema_rs.JSONSchema(
    {
        "$schema": "https://json-schema.org/draft-07/schema",
        "$id": "https://github.com/Stranger6667/jsonschema-rs/blob/master/jsonschema/meta_schemas/draft2020-12/meta/applicator.js",
    }
)

The following snippet does not crash on 3.12 (same schema with fewer characters in "$id").

import jsonschema_rs

jsonschema_rs.JSONSchema(
    {
        "$schema": "https://json-schema.org/draft-07/schema",
        "$id": "https://github.com/Stranger6667/jsonschema-rs/blob/master/jsonschema/meta_schemas/draft2020-12/meta/applicator.j",
    }
)

Error printed when running the first snippet.

thread '<unnamed>' panicked at /Users/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.100/src/ser.rs:2030:51:
byte index 112 is not a char boundary; it is inside '\0' (bytes 111..112) of `github.com/Stranger6667/jsonschema-rs/blob/master/jsonschema/meta_schemas/draft2020-12/meta/applicator.js?`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 190: invalid start byte
thread '<unnamed>' panicked at /Users/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.19.1/src/err/mod.rs:788:5:
Python API call failed
fatal runtime error: failed to initiate panic, error 5
zsh: abort      python test.py
@aMarcireau aMarcireau changed the title [python] Segfault on Python 3.12 [python] Panic on Python 3.12 Nov 6, 2023
@amw
Copy link

amw commented Nov 28, 2023

I can confirm this. Does anyone have a hint for what should be investigated or upgraded?

@Stranger6667
Copy link
Owner

Stranger6667 commented Nov 28, 2023

We need to update the string definitions to accommodate changes from Python 3.12 - https://github.com/Stranger6667/jsonschema-rs/blob/master/bindings/python/src/string.rs

Or, better, reuse some definitions from PyO3. Similar changes in orjson

@eirnym
Copy link

eirnym commented Feb 5, 2024

I agree. Running test suite reveals the same.

INTERNALERROR>     JSONSchema.from_str('{"minimum": 5}').validate,
INTERNALERROR>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> ValueError: Invalid string: expected value at line 1 column 1

@matemax
Copy link

matemax commented Feb 21, 2024

Any updates?
using jsonschema-rs with version 3.12 is difficult. No releases with wheel for 3.12 and this bug. don't know rust and can't help with this issue. We can't upgrade python version in our project =(

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

Successfully merging a pull request may close this issue.

5 participants