mmap extended slicing ignores the step; negative steps raise java.lang.IndexOutOfBoundsException

Offen
#1,367 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
64/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
java, python
Bereich
backend

Rechercherichtung

Start by running the three-line reproduction script on GraalPy and comparing it with CPython's output. The payload names no source files, so locate the mmap implementation by searching for the slice handling. CPython's test_mmap.MmapTests.test_extended_getslice is the target. Done when extended slices with positive and negative steps match bytearray and the negative-step case no longer raises a Java IndexOutOfBoundsException.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

I found this while benchmarking the conformance of alternative Python implementations against CPython: the same standard library cases and selected CPython tests run on CPython, PyPy, GraalPy and RustPython.

Reading a mmap.mmap slice with a step other than 1 returns the contiguous bytes instead of every n-th byte. A negative step raises a Java IndexOutOfBoundsException that is not catchable as a Python exception. mmap objects are documented to behave like bytearray, and CPython's test_mmap.MmapTests.test_extended_getslice covers this; it fails on GraalPy.

Reproduction
import mmap

data = bytes(range(10))
region = mmap.mmap(-1, len(data))
region[:] = data
print(region[::2].hex(), data[::2].hex())
print(region[1:7:3].hex(), data[1:7:3].hex())
print(region[::-1].hex(), data[::-1].hex())

CPython 3.12.15:

0002040608 0002040608
0104 0104
09080706050403020100 09080706050403020100

GraalPy:

0001020304 0002040608
0102 0104
java.lang.IndexOutOfBoundsException

The length of the result is right; the step is not applied. Assigning to an extended slice (region[::2] = b"xyz") works.

Versions
  • GraalPy 25.2.4 Community (Python 3.12.8), Linux x86-64 and macOS aarch64 standalone builds
  • GraalPy 25.6.5 Community (Python 3.13.14), macOS aarch64 standalone build

This report was drafted with the help of AI. The reproductions were run on the GraalPy versions listed above, and on CPython 3.12.15 for the expected output.

Vorherrschende Sprache
Python
Sterne
1.7k
Forks
167
Ø Merge
3 T. 11 Std.
Gemergte PRs (30 T.)
68

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus oracle/graalpython

Alle Issues in oracle/graalpython

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.