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
_json crash on scanner/encoder initialization error #51235
Comments
scanner_init() and encoder_init() don't manage errors correctly. scanner_init() gets context.encoding argument without checking context Example to reproduce the crash: encoder_init() copies a refence (for each argument) without incrementing Example to reproduce the crash: Attached patches for the crashes. |
About _json_encoder_init.patch, an alternative patch is to write
arguments references (addresses) in local variables, and only copy them
on success. Something like:
PyObject *arg;
if (!PyTuple_ParseArgs(..., &arg)) return NULL;
Py_INCREF(arg);
self->arg = arg; I prefered to write a shorter patch. Tell me if you prefer the alternative fix, and if you would like unit tests. |
Unit tests are definitely desireable! |
pitrou> Unit tests are definitely desireable! done pitou> I would also like the "alternate approach" fix, done. See the new patch. |
There is actually a Lib/json/tests/ directory contain all JSON tests, |
pitrou> There is actually a Lib/json/tests/ directory contain all My patch creates the file Lib/json/tests/test__json.py. Do you mean |
Ah, my bad, I thought it created the file in Lib/test. |
The tests could go in Lib/json/tests/test_speedups.py. |
New version of my patch:
|
Oops, you forget json-crash-2.patch, the patch was completly wrong. |
I wrote new patches to:
Is the patch now correct? Can you apply it? It doesn't still crash |
The patch looks good to me. |
This has been committed in r76708, r76710, r76711. Thank you! |
Could you please add a comment for test_make_encoder Victor? Invalid arguments are passed to c_make_encoder, but it raises a TypeError not because wrong types of argument, but because the number of arguments is insufficient. At first glance it looks as an error in the test. Only reading this issue give a hint that perhaps this is intentional. But there is no reference to this issue in the test. |
Oh wow, this issue was fixed 8 years ago and it's now closed! Please open a write issue, or maybe even propose directly a PR? (If you do, I will review it.) |
I would be happy to open such a PR, if you don't mind. |
It would be nice. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: