array_t::at() returns a misaligned reference when the stride is not a multiple of alignof(T)
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
🤖 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.
- Ngôn ngữ chính
- C++
- Star
- 18k
- Fork
- 2.3k
- Merge trung bình
- 5 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 53
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pybind/pybind11
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 3 ngày
-
triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
pybind/pybind11#5604 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 3 ngày
-
docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
pybind/pybind11#747 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 40/100
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của pybind/pybind11
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
patrick-hudson/put.gd-desktop#2044 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
uxlfoundation/oneDNN#6604 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug]: RoundToNearest truncates in plugins compiled with spcomp 1.13Có thể đã có người làm @fmu1337 đã nhận hôm nay. Đang mởBug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
alliedmodders/sourcemod#2627 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`Number` enum is not exportedĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày