Integer underflow and buffer overrun in detail::count_rows on disconnected distance matrices
Maintainer thường phản hồi trong vòng 3 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
- 72/100
Hướng nghiên cứu
Bắt đầu từ src/cpp_common/to_postgres.cpp tại detail::count_rows, sau đó đọc matrix_to_tuple và lệnh gọi pgr_alloc(tupcount, tuples) dùng để xác định kích thước bộ đệm. Thay phép trừ kích thước bằng việc đếm tường minh các ô hữu hạn nằm ngoài đường chéo, như issue đề xuất. Hoàn thành khi một unit test với ma trận không liên thông (bao gồm đường chéo không thể truy cập) trả về đúng số dòng và không có tràn bộ đệm.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Integer underflow and buffer overrun in detail::count_rows on disconnected or sparse distance matrices
Description
In src/cpp_common/to_postgres.cpp, detail::count_rows calculates the number of valid off-diagonal entries in an all-pairs distance matrix (pgr_johnson, pgr_floydWarshall):
size_t
count_rows(const std::vector<std::vector<double>> &matrix) {
int64_t count = 0;
for (size_t i = 0; i < matrix.size(); i++) {
count += std::count_if(
matrix[i].begin(), matrix[i].end(),
[](double value) {
return value != (std::numeric_limits<double>::max)();
});
}
return static_cast<size_t>(count) - matrix.size();
}
This implementation assumes that every diagonal entry matrix[i][i] is non-infinity (!= max()) and is counted in count. However, on disconnected graphs, sparse inputs, or subgraphs with unreachable self-distances:
-
Underallocation & Buffer Overrun: If any diagonal entry equals
max(),countdid not include that cell, yetmatrix.size()is still subtracted. As a result,count_rowsreturns fewer rows than the actual number of valid off-diagonal pairs.matrix_to_tuplethen iterates over all valid off-diagonal entries and writes past the end of thetuplesbuffer allocated bypgr_alloc(tupcount, tuples), resulting in memory corruption. -
Unsigned Integer Underflow: If
count < matrix.size()(for example, on an empty or largely unreachable graph where fewer thanNcells are finite),static_cast<size_t>(count) - matrix.size()underflows unsigned subtraction to a huge value (~1.84e19).pgr_allocthen attempts to allocate an astronomical amount of memory, terminating the PostgreSQL backend process with an out-of-memory error.
Expected Behavior
count_rows should count exactly the valid off-diagonal cells (i != j && matrix[i][j] != max()) without underflowing or underallocating.
Proposed Solution
Replace the subtraction assumption with an explicit off-diagonal count:
size_t
count_rows(const std::vector<std::vector<double>> &matrix) {
size_t count = 0;
for (size_t i = 0; i < matrix.size(); ++i) {
for (size_t j = 0; j < matrix[i].size(); ++j) {
if (i != j && matrix[i][j] != (std::numeric_limits<double>::max)()) {
++count;
}
}
}
return count;
}
I can open a PR with this fix and a unit test covering disconnected matrices.
- Ngôn ngữ chính
- C++
- Star
- 1.4k
- Fork
- 397
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
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 pgRouting/pgrouting
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Add details to CONTRIBUTING.mdĐang mởAdministrative Enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 3 ngày
-
points_input Developers docCó thể đã có người làm @withaman69 đã nhận 100 ngày trước. Đang mởC/C++ Developers Doc. good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
pgRouting/pgrouting#973 · 10 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
get_check_data developers docCó thể đã có người làm @withaman69 đã nhận 102 ngày trước. Đang mởC/C++ Developers Doc. good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
pgRouting/pgrouting#972 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
pickdeliver: Create and use process/driver pairCó thể đã có người làm @cvvergara đã nhận 6 ngày trước. Đang mởEnhancement Pick & Delivery
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của pgRouting/pgrouting
Issue tương tự
-
Độ 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 70/100
KLayout/klayout#2554 · 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 72/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 65/100
LaneDibello/Kotor-Patch-Manager#375 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày