array: unpickling an odd-length 'w' array across endianness raises ValueError (wrong UTF-16/UTF-32 item size)
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
array.array pickles carry a machine-format code so the receiver can decode
data from a different platform. The decoder's format table
(mformat_descriptors in Modules/arraymodule.c) stores a wrong item size
for the Unicode formats: UTF-16 entries say 4 bytes per item (actual: 2) and
UTF-32 entries say 8 (actual: 4).
The only consumer of that field is the length check on the cross-endian slow
path, so unpickling an odd-length 'w' array from a machine of the opposite
endianness fails:
import array
recon = array._array_reconstructor # what pickle calls
data = 'abc'.encode('utf-32-be') # 3 code points, big-endian
recon(array.array, 'w', 21, data) # 21 = UTF32_BE, on a little-endian machine
# ValueError: string length not a multiple of item size
Even lengths decode correctly, and same-endian pickles use the fast path that
skips the check, which is why this stayed hidden. On 3.13/3.14 the 'u'
typecode maps to the (equally wrong) UTF-16 entries on Windows.
Linked PRs
- gh-155851
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in Modules/arraymodule.c, in particolare nella tabella mformat_descriptors e nel percorso cross-endian di _array_reconstructor. Verifica che i dati UTF-16 e UTF-32 di lunghezza dispari con «w» o «u» possano essere deserializzati con pickle tra endianess diverse senza il ValueError relativo alla dimensione dell’elemento; il PR collegato gh-155851 indica che il lavoro è già in corso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c, python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 25/100