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 crashes during encoding resized lists #60432

Closed
serhiy-storchaka opened this issue Oct 14, 2012 · 14 comments
Closed

JSON crashes during encoding resized lists #60432

serhiy-storchaka opened this issue Oct 14, 2012 · 14 comments
Labels
extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@serhiy-storchaka
Copy link
Member

BPO 16228
Nosy @rhettinger, @jcea, @etrepum, @pitrou, @ezio-melotti, @asvetlov, @serhiy-storchaka
Files
  • json_encode_resized_list.patch
  • 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 2012-11-01.19:08:54.492>
    created_at = <Date 2012-10-14.09:56:18.708>
    labels = ['extension-modules', 'type-crash']
    title = 'JSON crashes during encoding resized lists'
    updated_at = <Date 2012-11-01.20:03:22.569>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2012-11-01.20:03:22.569>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-11-01.19:08:54.492>
    closer = 'pitrou'
    components = ['Extension Modules']
    creation = <Date 2012-10-14.09:56:18.708>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['27563']
    hgrepos = []
    issue_num = 16228
    keywords = ['patch', 'needs review']
    message_count = 14.0
    messages = ['172867', '172869', '174414', '174422', '174439', '174442', '174443', '174445', '174451', '174454', '174455', '174461', '174465', '174467']
    nosy_count = 8.0
    nosy_names = ['rhettinger', 'jcea', 'bob.ippolito', 'pitrou', 'ezio.melotti', 'asvetlov', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue16228'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

    @serhiy-storchaka
    Copy link
    Member Author

    JSON encoding crash if the source list resized in process of encoding. This can be happen unintentionally in multithreaded code.

    Simple crash code:

    import json
    a = [object()] * 10
    def crasher(obj):
        del a[-1]
    
    json.dumps(a, default=crasher)

    @serhiy-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 14, 2012
    @serhiy-storchaka
    Copy link
    Member Author

    Here is a patch.

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Nov 1, 2012

    The patch LGTM except I cannot reproduce crash on unmodified sources with running applied test.

    @serhiy-storchaka
    Copy link
    Member Author

    Of course, this kind of bugs can cause unpredictable behavior, they do not have to lead to an immediate crash. This depends from the platform, the compiler and its options. On my computers the test always crashed, this is the maximum that I can say.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 1, 2012

    New changeset 3672db224eb3 by Antoine Pitrou in branch '3.2':
    Issue bpo-16228: Fix a crash in the json module where a list changes size while it is being encoded.
    http://hg.python.org/cpython/rev/3672db224eb3

    New changeset 7528c02b8d52 by Antoine Pitrou in branch '3.3':
    Issue bpo-16228: Fix a crash in the json module where a list changes size while it is being encoded.
    http://hg.python.org/cpython/rev/7528c02b8d52

    New changeset ab65509b8443 by Antoine Pitrou in branch 'default':
    Issue bpo-16228: Fix a crash in the json module where a list changes size while it is being encoded.
    http://hg.python.org/cpython/rev/ab65509b8443

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 1, 2012

    New changeset 33ae62a4ecf5 by Antoine Pitrou in branch '2.7':
    Issue bpo-16228: Fix a crash in the json module where a list changes size while it is being encoded.
    http://hg.python.org/cpython/rev/33ae62a4ecf5

    @pitrou
    Copy link
    Member

    pitrou commented Nov 1, 2012

    Thank you for noticing this, and for writing a patch.

    @pitrou pitrou closed this as completed Nov 1, 2012
    @asvetlov
    Copy link
    Contributor

    asvetlov commented Nov 1, 2012

    Hi, I'm ok with patch but I guess to add some comment in C code to prevent, hmm, back optimization from upcoming contributor.
    The same for bpo-16230

    @pitrou
    Copy link
    Member

    pitrou commented Nov 1, 2012

    Hi, I'm ok with patch but I guess to add some comment in C code to
    prevent, hmm, back optimization from upcoming contributor.
    The same for bpo-16230

    But that's what tests are for.

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Nov 1, 2012

    As I said tests was not crashed on my linux 64 bit Ubuntu with buggy code.

    @pitrou
    Copy link
    Member

    pitrou commented Nov 1, 2012

    As I said tests was not crashed on my linux 64 bit Ubuntu with buggy code.

    They crashed duly here in debug mode (64-bit Linux).

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Nov 1, 2012

    I have python built with Py_DEBUG (./configure --with-pydebug)
    What I' missed?
    I'm ok with status quo but just want to understand how to configure my build properly.

    @pitrou
    Copy link
    Member

    pitrou commented Nov 1, 2012

    I have python built with Py_DEBUG (./configure --with-pydebug)
    What I' missed?
    I'm ok with status quo but just want to understand how to configure my build properly.

    Well, I don't know. Perhaps a different compiler version, a different
    libc, or perhaps you got (un)lucky.

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Nov 1, 2012

    Ok. Thanks.

    @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
    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

    3 participants