JIT global-to-constant promotion doesn't properly validate the globals dictionary at runtime · Issue #136154 · python/cpython · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

JIT global-to-constant promotion doesn't properly validate the globals dictionary at runtime #136154

Open
@brandtbucher

Description

@brandtbucher

Bug report

This code raises a NameError with the JIT disabled, and succeeds with the JIT enabled:

import types

GLOBAL = 42

def make_f():
    def f():
        return GLOBAL
    return f

make_f_with_bad_globals = types.FunctionType(make_f.__code__, {})

def jitted(funcs):
    for func in funcs:
        func()

def main():
    # Make a "good" f:
    f = make_f()
    # Compile jitted for the "good" f:
    jitted([f] * 4096)
    # This "bad" f has different globals, but the *same* code/function versions:
    f_with_bad_globals = make_f_with_bad_globals()
    # A "good" f to enter the JIT code, and a "bad" f to trigger the bug:
    jitted([f, f_with_bad_globals])

main()

We're relying on the function version to guarantee the correct globals. Functions that are created from the same code object share the same function version, but don't necessarily share the same globals.

The fix is probably to insert runtime checks for the identity of the globals dictionary (instead of the function version) in remove_globals. An identity check is safe, since if the original globals dict is deallocated then the trace will be invalidated anyways.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      TMZ Celebrity News – Breaking Stories, Videos & Gossip

      Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

      Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

      🎥 Watch TMZ Live

      TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.