array_t::at() returns a misaligned reference when the stride is not a multiple of alignof(T)
Les mainteneurs répondent en général sous 3 jours
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
Piste de recherche
The misaligned reference comes from array_t::at() and mutable_at() in include/pybind11/numpy.h, around line 1526. Start with the element address calculation there, then run test_at_stride_not_multiple_of_itemsize under the UBSan CI job, which currently deselects it. Done means the test passes under UBSan without the deselect, and either a throw for misaligned elements or an alignment check at array creation has been chosen and implemented.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
🤖 AI text below 🤖
Since #6241, array_t<T>::at() and mutable_at() support strides that are not a multiple of sizeof(T). They return a T & to the element. If the stride is not a multiple of alignof(T), that reference is misaligned. This is undefined behavior. It works on x86 and arm64, but it can fail on platforms that require aligned access, and UBSan reports it:
include/pybind11/numpy.h:1526: runtime error: reference binding to misaligned address 0x00000a5cf433 for type 'const short unsigned int', which requires 2 byte alignment
Reproducer (from test_at_stride_not_multiple_of_itemsize):
packed = np.zeros(3, dtype=[("a", np.uint16), ("b", np.uint8)])
m.at_t(packed["a"], 1) # stride 3, element 1 is at an odd address
A reference cannot point to a misaligned T. Possible fixes:
- Throw when the element address is not aligned for
T. - Throw when the array is not aligned (
NPY_ARRAY_ALIGNED), possibly as a check when thearray_tis created.
The UBSan CI job deselects this test until this is fixed.
- Langage dominant
- C++
- Étoiles
- 18k
- Forks
- 2.3k
- Merge moyen
- 5 j 7 h
- PR mergées (30 j)
- 53
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de pybind/pybind11
-
triage
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 3 jours
-
triage
Difficulté 1/5 Moins d'une heure Accessibilité débutants 62/100
pybind/pybind11#5604 · 1 commentaire ·
Les mainteneurs répondent en général sous 3 jours
-
triage
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 3 jours
-
docs
Difficulté 2/5 1-3 heures Accessibilité débutants 60/100
pybind/pybind11#747 · 2 commentaires ·
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 3/5 1-2 jours Accessibilité débutants 40/100
Les mainteneurs répondent en général sous 3 jours
Toutes les issues de pybind/pybind11
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
patrick-hudson/put.gd-desktop#2044 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
uxlfoundation/oneDNN#6604 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
[Bug]: RoundToNearest truncates in plugins compiled with spcomp 1.13Peut-être pris @fmu1337 l’a pris aujourd’hui. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
alliedmodders/sourcemod#2627 ·
Les mainteneurs répondent en général sous 1 jour
-
`Number` enum is not exportedOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour