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

assertion failure in json, in case _json.make_encoder() received a bad encoder() argument #75686

Closed
orenmn mannequin opened this issue Sep 18, 2017 · 3 comments
Closed
Labels
3.7 (EOL) end of life extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@orenmn
Copy link
Mannequin

orenmn mannequin commented Sep 18, 2017

BPO 31505
Nosy @serhiy-storchaka, @orenmn
PRs
  • bpo-31505: Fix an assertion failure in json, in case _json.make_encoder() received a bad encoder() argument #3643
  • [3.6] bpo-31505: Fix an assertion failure in json, in case _json.make_encoder() received a bad encoder() argument. (GH-3643) #3777
  • 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 = None
    closed_at = <Date 2017-09-27.05:41:43.824>
    created_at = <Date 2017-09-18.08:57:43.748>
    labels = ['extension-modules', '3.7', 'type-crash']
    title = 'assertion failure in json, in case _json.make_encoder() received a bad encoder() argument'
    updated_at = <Date 2017-09-27.05:41:43.823>
    user = 'https://github.com/orenmn'

    bugs.python.org fields:

    activity = <Date 2017-09-27.05:41:43.823>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-09-27.05:41:43.824>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2017-09-18.08:57:43.748>
    creator = 'Oren Milman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31505
    keywords = ['patch']
    message_count = 3.0
    messages = ['302428', '302836', '303094']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'Oren Milman']
    pr_nums = ['3643', '3777']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue31505'
    versions = ['Python 3.7']

    @orenmn
    Copy link
    Mannequin Author

    orenmn mannequin commented Sep 18, 2017

    The following code causes an assertion failure:

    import _json
    def _bad_encoder(*args):
        return None
    
    enc = _json.make_encoder(None, None, _bad_encoder, None,
                             'foo', 'bar', None, None, None)
    
    enc(obj='spam', _current_indent_level=4)

    This is because encoder_new() (in Modules/_json.c) assumes that the received
    encoder() argument is a function that returns a string, and stores it in the
    new PyEncoderObject.
    When encoder_encode_string() is called (by encoder_listencode_obj()), it
    returns whatever the stored encoder() returned, assuming it returned a string.
    Then, encoder_listencode_obj() passes this value to _steal_accumulate(), which
    passes it to _PyAccu_Accumulate(), which asserts it is a string.

    Similarly, the following code also causes an assertion failure (only the obj
    argument is different):

    import _json
    def _bad_encoder(*args):
        return None
    
    enc = _json.make_encoder(None, None, _bad_encoder, None,
                             'foo', 'bar', None, None, None)
    
    enc(obj={'spam': 42}, _current_indent_level=4)

    In this case, encoder_listencode_dict() passes whatever encoder_encode_string()
    returned, to _PyAccu_Accumulate(), which asserts it is a string.

    @orenmn orenmn mannequin added 3.7 (EOL) end of life extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump labels Sep 18, 2017
    @orenmn orenmn mannequin changed the title assertion failure in _json.make_encoder() in case of a bad encoder() argument assertion failure in json, in case _json.make_encoder() received a bad encoder() argument Sep 18, 2017
    @serhiy-storchaka
    Copy link
    Member

    New changeset 2b382dd by Serhiy Storchaka (Oren Milman) in branch 'master':
    bpo-31505: Fix an assertion failure in json, in case _json.make_encoder() received a bad encoder() argument. (bpo-3643)
    2b382dd

    @serhiy-storchaka
    Copy link
    Member

    New changeset 7c24e99 by Serhiy Storchaka (Miss Islington (bot)) in branch '3.6':
    [3.6] bpo-31505: Fix an assertion failure in json, in case _json.make_encoder() received a bad encoder() argument. (GH-3643) (bpo-3777)
    7c24e99

    @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
    3.7 (EOL) end of life extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant