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

Aberta
#1,367 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
64/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
java, python
Domínio
backend

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Python
Estrelas
1.7k
Forks
167
Merge médio
3d 11h
PRs com merge (30d)
68

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de oracle/graalpython

Todas as issues de oracle/graalpython

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.