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

_json: fix raise_errmsg(), py_encode_basestring_ascii() and linecol() #47873

Closed
vstinner opened this issue Aug 20, 2008 · 12 comments
Closed

_json: fix raise_errmsg(), py_encode_basestring_ascii() and linecol() #47873

vstinner opened this issue Aug 20, 2008 · 12 comments
Assignees
Labels
release-blocker stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@vstinner
Copy link
Member

BPO 3623
Nosy @warsaw, @etrepum, @amauryfa, @orsenthil, @vstinner, @tiran, @devdanzin, @avassalotti, @benjaminp
Files
  • _json.patch: Fix descibed bugs
  • _json26.patch: raise_errmsg(): fix when errmsg() fails
  • json_test.patch: Write an unit test for the two crashs
  • 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:

    assignee = 'https://github.com/etrepum'
    closed_at = <Date 2008-10-16.21:18:02.804>
    created_at = <Date 2008-08-20.22:58:44.113>
    labels = ['library', 'type-crash', 'release-blocker']
    title = '_json: fix raise_errmsg(), py_encode_basestring_ascii() and linecol()'
    updated_at = <Date 2008-10-16.21:28:27.322>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2008-10-16.21:28:27.322>
    actor = 'benjamin.peterson'
    assignee = 'bob.ippolito'
    closed = True
    closed_date = <Date 2008-10-16.21:18:02.804>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2008-08-20.22:58:44.113>
    creator = 'vstinner'
    dependencies = []
    files = ['11181', '11613', '11718']
    hgrepos = []
    issue_num = 3623
    keywords = ['patch', 'needs review']
    message_count = 12.0
    messages = ['71588', '71598', '71599', '72460', '72614', '73866', '73869', '74100', '74422', '74861', '74864', '74865']
    nosy_count = 9.0
    nosy_names = ['barry', 'bob.ippolito', 'amaury.forgeotdarc', 'orsenthil', 'vstinner', 'christian.heimes', 'ajaksu2', 'alexandre.vassalotti', 'benjamin.peterson']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue3623'
    versions = ['Python 3.0']

    @vstinner
    Copy link
    Member Author

    _json module of python 3.0 has some bugs.

    (a) [_json.c] raise_errmsg() calls json.decoder.errmsg() from Python
    module, but this function may fails. If it fails, error should be be
    set to NULL. Example:

    >>> import _json
    >>> _json.scanstring(b"xxx", 1, "xxx")
    Erreur de segmentation (core dumped)

    => json.decoder.errmsg() calls linecol() which raise an error on
    b"xxx".index("\n").

    (b) [_json.c] py_encode_basestring_ascii() calls PyBytes_Check(rval)
    but rval can be NULL if ascii_escape_str() or ascii_escape_unicode()
    fails. Example:

    >>> import _json
    >>> _json.encode_basestring_ascii(b"xx\xff")
    Erreur de segmentation (core dumped)

    (c) [Lib/json/decoder.py] linecol() doesn't support bytes, but it's
    called with bytes argument: see point (a). For an example, see point
    (a).

    @vstinner vstinner added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Aug 20, 2008
    @etrepum
    Copy link
    Mannequin

    etrepum mannequin commented Aug 21, 2008

    That patch looks ok to me, but I'm not at all familiar with the changes in
    python 3.0 yet. Is this something that needs to be backported to 2.6?

    @benjaminp
    Copy link
    Contributor

    Christian, I believe, did the original 3.0 porting, so he can probably
    shed some light on this.

    @warsaw
    Copy link
    Member

    warsaw commented Sep 4, 2008

    Deferring until rc2

    @orsenthil
    Copy link
    Member

    bpo-3763 mentions about the similar problem with json library.
    The traceback posted illustrates the issue (c) mentioned here:

    File "C:\Python30\lib\json\decoder.py", line 30, in errmsg
    lineno, colno = linecol(doc, pos)
    File "C:\Python30\lib\json\decoder.py", line 21, in linecol
    lineno = doc.count('\n', 0, pos) + 1
    TypeError: expected an object with the buffer interface

    @vstinner
    Copy link
    Member Author

    Is this something that needs to be backported to 2.6?

    Hum, here is a part of my patch which can be applied to python 2.6. I
    don't know if it fixes real bugs, but the code looks better with the
    patch: PyErr_SetObject() and Py_DECREF() should not be called with
    NULL argument.

    @amauryfa
    Copy link
    Member

    _json26.patch looks good, and is necessary, because the called python
    function has more than one way to raise an exception (KeyboardInterrupt
    at least...)

    I would just add another minor change: this raise_errmsg() function
    should be made static.

    @etrepum
    Copy link
    Mannequin

    etrepum mannequin commented Sep 30, 2008

    I applied the changes proposed in _json26.patch to simplejson and they
    worked perfectly fine. Again I'm not the best judge of python 3.0 code
    because I have not made myself familiar with the API changes so someone
    else should review it (but it's probably fine).

    @avassalotti
    Copy link
    Member

    The patch looks good to me.

    You may want to fix the refleak in the PyList_Append() calls (I counted
    4) too:

                if (PyList_Append(chunks, chunk)) {
                    goto bail;
                }

    should be:

                if (PyList_Append(chunks, chunk)) {
                    Py_DECREF(chunk);
                    goto bail;
                }

    Also, line 384 and 548:

        Py_DECREF(chunks);
        chunks = NULL;

    should changed to

        Py_CLEAR(chunks);

    @benjaminp
    Copy link
    Contributor

    Fixed in r66932 and r66934.

    @benjaminp
    Copy link
    Contributor

    Refleak was fixed in r66934.

    @benjaminp
    Copy link
    Contributor

    I mean r66938. Sorry!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    release-blocker stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    6 participants