BUG: StringStore and ListStore resize erase data when the tuple-shape product overflows
Maintainer thường phản hồi trong vòng 6 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 57/100
Hướng nghiên cứu
Read src/simplnx/DataStructure/StringStore.cpp and src/simplnx/DataStructure/ListStore.hpp at the referenced resize functions, then inspect EmptyDataStore::CheckedPlaceholderProduct for zero dimension handling. Add the overflow rejection while preserving the existing store, and apply checked counting in the StringStore shape constructor. Add or run the cases in test/StoreResizeContractsTest.cpp; done means both resizes return error -6035 without changing shape, tuple count, or values.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
StringStore::resizeTuples() and ListStore::resizeTuples() do not check the tuple-shape product for overflow. When the product does not fit in usize, it wraps around. The resize then deletes the stored values, records the requested shape, and returns a valid Result<>.
For example, a StringStore with 3 strings that is resized to the tuple shape {2^63, 2} on a 64-bit platform returns success. After the call, it has 0 tuples and no strings, but getTupleShape() returns {9223372036854775808, 2}. ListStore behaves in the same way.
The expected behavior is the documented contract of resizeTuples(): return error -6035 and keep the prior store (shape, tuple count and values).
Occurs at develop commit 547f28a75e6325358fe7823e6dcb00defda81cd1.
Steps to Reproduce
- Build
simplnx_testfromdevelop(Release, 64-bit). - Add the two tests in Verification Unit Test to
test/StoreResizeContractsTest.cpp. - Make a
StringStorewith the strings"alpha","beta"and"gamma"and the tuple shape{3}. - Call
resizeTuples({usize{1} << 63, 2}). - The call returns a valid
Result<>, the store has 0 tuples, and the tuple shape is{9223372036854775808, 2}. - Do steps 3 to 5 again with a
ListStore<int32>that has 3 lists. The result is the same.
Cause
Both functions compute the tuple count with std::accumulate and no overflow check, and then resize the container to the wrapped count:
const usize numTuples = std::accumulate(newTupleShape.cbegin(), newTupleShape.cend(), static_cast<usize>(1), std::multiplies<>());
m_Data.resize(numTuples); // m_Array.resize(numTuples) in ListStore
m_TupleShape = std::move(newTupleShape);
m_NumTuples = numTuples;
2^63 * 2 is 2^64, which wraps to 0. resize(0) succeeds and deletes every element, so the catch block that returns -6035 never runs.
The StringStore(const ShapeType& tupleShape) constructor computes the count in the same way (StringStore.cpp L16).
Verification Unit Test
File: test/StoreResizeContractsTest.cpp
TEST_CASE("StringStore resize rejects an overflowing tuple shape", "[simplnx][StoreResizeContracts]")
{
StringStore store(std::vector<std::string>{"alpha", "beta", "gamma"}, ShapeType{3});
// The tuple-shape product 2^63 * 2 = 2^64 does not fit a 64-bit usize.
const ShapeType overflowingTupleShape = {usize{1} << 63, 2};
Result<> result;
REQUIRE_NOTHROW(result = store.resizeTuples(overflowingTupleShape));
CHECK(result.invalid());
CHECK(store.getTupleShape() == ShapeType{3});
REQUIRE(store.getNumberOfTuples() == 3);
CHECK(store.getValue(0) == "alpha");
CHECK(store.getValue(1) == "beta");
CHECK(store.getValue(2) == "gamma");
REQUIRE(result.errors().size() == 1);
CHECK(result.errors().front().code == -6035);
}
TEST_CASE("ListStore resize rejects an overflowing tuple shape", "[simplnx][StoreResizeContracts]")
{
ListStore<int32> store(ShapeType{3});
store.setList(0, std::vector<int32>{7, 9});
store.setList(1, std::vector<int32>{-4});
store.setList(2, std::vector<int32>{1, 2, 3});
// The tuple-shape product 2^63 * 2 = 2^64 does not fit a 64-bit usize.
const ShapeType overflowingTupleShape = {usize{1} << 63, 2};
Result<> result;
REQUIRE_NOTHROW(result = store.resizeTuples(overflowingTupleShape));
CHECK(result.invalid());
CHECK(store.getTupleShape() == ShapeType{3});
REQUIRE(store.getNumberOfTuples() == 3);
CHECK(store.getList(0) == std::vector<int32>{7, 9});
CHECK(store.getList(1) == std::vector<int32>{-4});
CHECK(store.getList(2) == std::vector<int32>{1, 2, 3});
REQUIRE(result.errors().size() == 1);
CHECK(result.errors().front().code == -6035);
}
Command (from the build directory):
ctest -R "^(StringStore|ListStore) resize rejects an overflowing tuple shape$" --output-on-failure
Failure on develop (macOS arm64, AppleClang, Release). ListStore fails with the same three lines at L127-L129:
StoreResizeContractsTest.cpp:106: FAILED:
CHECK( result.invalid() )
with expansion:
false
StoreResizeContractsTest.cpp:107: FAILED:
CHECK( store.getTupleShape() == ShapeType{3} )
with expansion:
{ 9223372036854775808 (0x8000000000000000), 2 } == { 3 }
StoreResizeContractsTest.cpp:108: FAILED:
REQUIRE( store.getNumberOfTuples() == 3 )
with expansion:
0 == 3
0% tests passed, 2 tests failed out of 2
Proposed Fix
- In
StringStore::resizeTuples()andListStore::resizeTuples(), compute the tuple count with an overflow check beforeresize(). On overflow, return error -6035 with a message that says the tuple count does not fit, and do not change the store. - A shape that contains a zero dimension has a count of zero. Check for a zero dimension before the multiplication, as
EmptyDataStore::CheckedPlaceholderProductdoes, so that{SIZE_MAX, 2, 0}resizes to 0 tuples. - Use the same check in the
StringStore(const ShapeType&)constructor, and throw there because a constructor cannot return aResult<>. - A shared checked-product helper for all stores would keep the rule the same everywhere.
Notes
- PR #1834 adds this check to
DataStore::resizeTuples()only. - The
DataStoreconstructors have the same unchecked product (#1883).
- Ngôn ngữ chính
- C++
- Star
- 18
- Fork
- 15
- Merge trung bình
- 4 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 42
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 BlueQuartzSoftware/simplnx
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
BlueQuartzSoftware/simplnx#1987 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
BlueQuartzSoftware/simplnx#1980 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
Testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
BlueQuartzSoftware/simplnx#1979 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
BlueQuartzSoftware/simplnx#1978 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
BlueQuartzSoftware/simplnx#1945 ·
Maintainer thường phản hồi trong vòng 6 ngày
Tất cả issue của BlueQuartzSoftware/simplnx
Issue tương tự
-
bug 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 1 ngày
-
26.04 bug dark-mode Easy Hack impress symptom: visual
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
CollaboraOnline/online#16421 · 1 bình luận ·
-
area/cs bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
ydb-platform/ydb#59881 · 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 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation enhancement lua server
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100