[C++][Compute] year_month_day writes past its child buffers for inputs longer than 32 rows (wrong results, heap corruption)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 74/100
Hướng nghiên cứu
Đọc YearMonthDay::Exec trong cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc, bắt đầu từ lệnh gọi Reserve(1) trên ba Int64Builder con, rồi so sánh với ISOCalendar::Exec trong cùng tệp, hàm này dành in.length cho mỗi con. Thay đổi việc dành bộ nhớ cho khớp và xác nhận đường đi UnsafeAppend của visitor giờ nằm trong giới hạn. Hoàn thành khi một kiểm thử với hơn 32 dòng (các fixture hiện có ngắn hơn) trả về giá trị đúng cho đầu vào date32, date64 và timestamp, và lỗi ghi ngoài giới hạn do fuzzing/valgrind phát hiện không còn nữa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug, including details regarding any error messages, version, and platform.
year_month_day returns wrong values for any input with more than 32 rows, and the kernel writes past the end of its output buffers, corrupting the heap.
import pyarrow as pa
import pyarrow.compute as pc
dates = pa.array(range(40), type=pa.int32()).view(pa.date32())
ymd = pc.year_month_day(dates)
for d, r in list(zip(dates.to_pylist(), ymd.to_pylist()))[30:36]:
print(d, r)
Output with pyarrow 26.0.1 on Linux x86_64:
1970-01-31 {'year': 1970, 'month': 1, 'day': 31}
1970-02-01 {'year': 1970, 'month': 2, 'day': 1}
1970-02-02 {'year': 0, 'month': 0, 'day': 0}
1970-02-03 {'year': 0, 'month': 0, 'day': 0}
1970-02-04 {'year': 0, 'month': 0, 'day': 0}
1970-02-05 {'year': 0, 'month': 0, 'day': 0}
Every row from index 32 on is wrong. The first rows of the month and day children are overwritten too: rows 0-7 come back as (1970, 1970, 2). On 1,000,000 dates, row 0 comes back as {'year': 1970, 'month': 1970, 'day': 1970}. While fuzzing compute kernels, I also saw later, unrelated calls in the same process segfault.
All accepted input types are affected: date32, date64, and timestamp with or without a time zone. I reproduced this in pyarrow 12.0.1, 15.0.2, 18.1.0, 21.0.0, 24.0.0 and 26.0.1. year, month, day and iso_calendar return correct results for the same inputs.
Cause. In YearMonthDay::Exec, each of the three child Int64Builders reserves only one element (scalar_temporal_unary.cc#L384):
RETURN_NOT_OK(field_builders[i]->Reserve(1));
The visitor then appends every value with UnsafeAppend, which does not check capacity. The builder rounds the reservation up to its 32-element minimum, so rows after the 32nd are written past the allocation. Null rows go through StructBuilder::AppendNull, which grows the children, so inputs with nulls show fewer wrong rows but are still affected. ISOCalendar::Exec builds the same kind of struct and reserves in.length for each child (#L1547).
Valgrind, run with ARROW_DEFAULT_MEMORY_POOL=system, reports the out-of-bounds write:
Invalid write of size 8
at ...YearMonthDayVisitValueFunction<..., arrow::Date32Type, ...>::Get(...)::{lambda(int)#1}
by ...YearMonthDay<std::chrono::duration<int, std::ratio<86400l, 1l> >, arrow::Date32Type>::Exec(...)
Address 0x1054a580 is 0 bytes after a block of size 256 alloc'd
256 bytes is 32 int64 values. The existing year_month_day tests use fixtures shorter than 32 rows, so they don't exercise this.
Component(s)
C++
- Ngôn ngữ chính
- C++
- Star
- 17.3k
- Fork
- 4.5k
- Merge trung bình
- 3 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 90
Chuẩn bị môi trường
- Có Dockerfile hoặc 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 apache/arrow
-
[R] abandon_ship() looks up `call` with an inheriting get(), so its "no call" guard never firesCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởComponent: R
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[C++][Python][Docs] Some compute functions are missing from the docsCó thể đã có người làm @rajbhatt2406-collab đã nhận 1 ngày trước. Đang mởComponent: C++ Component: Documentation Component: Python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/arrow#55762 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Component: C++ Type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Component: Continuous Integration Component: Developer Tools Type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
apache/arrow#55672 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Component: Python Type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
apache/arrow#55659 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Missing repro Platform: Android
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
software-mansion/react-native-reanimated#11554 · 1 bình luận ·
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 85/100
Niko1221/Strata#7211 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
sleepyviper1213/redis#52 ·