GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Negative indexing in free-threading can access data that never lived at that index · Issue #130744 · python/cpython

Negative indexing in free-threading can access data that never lived at that index #130744

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Negative indexing in free-threading can access data that never lived at that index#130744
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@tom-pytel
tom-pytel
opened on Mar 1, 2025
Issue body actions

Bug report

Bug description:

The place that negative indices for lists are offset currently in the free-threaded build can cause data to be returned that never actually resided at that offset (negatively speaking) if the list is modified during the access (either before or after the modification). Is this an issue?

cpython/Objects/listobject.c

Line 3581 in 5326c27

i += PyList_GET_SIZE(self);

Reproducer (it will happen eventually):

import re
import threading


def ins1(b, l):
    b.wait()
    l.insert(0, 'potato')

def get_secret(b, l):
    b.wait()
    assert l[-1] != 'super secret password'


def check(funcs, *args):
    barrier = threading.Barrier(len(funcs))
    thrds = []

    for func in funcs:
        thrd = threading.Thread(target=func, args=(barrier, *args))

        thrds.append(thrd)
        thrd.start()

    for thrd in thrds:
        thrd.join()


if __name__ == "__main__":
    while True:
        check([ins1] + [get_secret] * 10, ['super secret password', 'tomato'])

Output:

$ ./python ../check.py 
Exception in thread Thread-38474 (get_secret):
Traceback (most recent call last):
  File "/home/tom/work/cpython/free/cp/Lib/threading.py", line 1054, in _bootstrap_inner
    self.run()
    ~~~~~~~~^^
  File "/home/tom/work/cpython/free/cp/Lib/threading.py", line 996, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tom/work/cpython/free/cp/../check.py", line 11, in get_secret
    assert l[-1] != 'super secret password'
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Activity

  1. tom-pytel
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Mar 1, 2025
  2. tom-pytel commented on Mar 1, 2025

    @tom-pytel
    tom-pytel
    on Mar 1, 2025
    ContributorAuthor
    More actions

    ping @colesbury

  3. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    topic-free-threading
    on Mar 1, 2025
  4. colesbury commented on Mar 3, 2025

    @colesbury
    colesbury
    on Mar 3, 2025
    Contributor
    More actions

    We can document this, but I don't think we should change the implementation.

  5. tom-pytel
    closed this as not plannedon Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.