Description
ujson 5.10.1 raises a SystemError instead of JSONDecodeError when parsing a malformed JSON string.
Steps to Reproduce
#!/usr/bin/python3
import ujson
def poc():
"""Proof of Concept for ujson SystemError bug
Expected: JSONDecodeError
Actual: SystemError
"""
hex_string = "7b7b2261223a2262227d3a2263227d"
bytes_data = bytes.fromhex(hex_string)
json_str = bytes_data.decode('utf-8')
try:
ujson_data = ujson.loads(json_str)
except (ValueError, TypeError) as e:
print(f"Expected error: {type(e).__name__}: {str(e)}")
return
except SystemError as e:
print(f"Bug triggered! SystemError: {str(e)}")
import traceback
traceback.print_exc()
return
except Exception as e:
print(f"Unexpected error: {type(e).__name__}: {str(e)}")
return
if __name__ == "__main__":
poc()
Expected Behavior
Should raise JSONDecodeError or ValueError.
Actual Behavior
Raises SystemError indicating an internal C extension error.
$ python3 poc.py
Bug triggered! SystemError: <built-in function loads> returned a result with an exception set
TypeError: unhashable type: 'dict'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "ultrajson/poc.py", line 16, in poc
ujson_data = ujson.loads(json_str)
SystemError: <built-in function loads> returned a result with an exception set
Impact
This bug could potentially lead to unexpected program behavior and makes error handling more difficult.
Description
ujson 5.10.1 raises a SystemError instead of JSONDecodeError when parsing a malformed JSON string.
Steps to Reproduce
Expected Behavior
Should raise
JSONDecodeErrororValueError.Actual Behavior
Raises
SystemErrorindicating an internal C extension error.Impact
This bug could potentially lead to unexpected program behavior and makes error handling more difficult.