BUG: DataStore constructors accept a tuple shape whose product overflows
メンテナーはふだん 6 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Read src/simplnx/DataStructure/DataStore.hpp, focusing on both constructors and resizeTuples(), and review EmptyDataStore::CheckedPlaceholderProduct in src/simplnx/DataStructure/EmptyDataStore.hpp for the zero-dimension rule. Start by checking the existing DataStore tests in test/DataArrayTest.cpp; add coverage for overflowing tuple, component, element, and byte counts in both constructors. Done when those cases reject overflow while shapes containing a zero dimension remain valid.
索引モデルが issue の本文から書いたものです。
説明
Problem
The DataStore constructors do not check the tuple-shape product or the component-shape product for overflow. When a product does not fit in usize, the count wraps around. The store then allocates a buffer for the wrapped count, but it keeps the original shape.
For example, DataStore<int32>({2^63, 2}, {1}, 7) succeeds on a 64-bit platform with 0 tuples and 0 values, and getTupleShape() returns {9223372036854775808, 2}. The expected behavior is that the constructor rejects the shape. Every later operation that uses the shape and the count together gets inconsistent values.
Occurs at develop commit 547f28a75e6325358fe7823e6dcb00defda81cd1.
Steps to Reproduce
- Build
simplnx_testfromdevelop(Release, 64-bit). - Add the test in Verification Unit Test to
test/DataArrayTest.cpp. - Construct
DataStore<int32>with the tuple shape{usize{1} << 63, 2}, the component shape{1}and the initial value7. - The constructor returns normally. No exception is thrown.
Cause
The (tupleShape, componentShape, initValue) constructor computes both counts with std::accumulate and no overflow check, then allocates getSize() values:
, m_NumComponents(std::accumulate(m_ComponentShape.cbegin(), m_ComponentShape.cend(), static_cast<usize>(1), std::multiplies<>()))
, m_NumTuples(std::accumulate(m_TupleShape.cbegin(), m_TupleShape.cend(), static_cast<usize>(1), std::multiplies<>()))
...
m_Data = std::unique_ptr<value_type[]>(new value_type[this->getSize()]);
2^63 * 2 is 2^64, which wraps to 0. getSize() is then 0, so new value_type[0] succeeds.
The constructor that takes ownership of a buffer computes the counts in the same way:
getNumberOfComponents() * getNumberOfTuples() (the element count) and the byte count of the allocation are not checked either.
Verification Unit Test
File: test/DataArrayTest.cpp
TEST_CASE("DataStore constructor rejects an overflowing tuple shape", "[simplnx][DataStore]")
{
// The tuple-shape product 2^63 * 2 = 2^64 does not fit a 64-bit usize.
const ShapeType overflowingTupleShape = {usize{1} << 63, 2};
REQUIRE_THROWS(DataStore<int32>(overflowingTupleShape, ShapeType{1}, 7));
}
Command (from the build directory):
ctest -R "^DataStore constructor rejects an overflowing tuple shape$" --output-on-failure
Failure on develop (macOS arm64, AppleClang, Release):
DataArrayTest.cpp:860: FAILED:
REQUIRE_THROWS( DataStore<int32>(overflowingTupleShape, ShapeType{1}, 7) )
because no exception was thrown where one was expected:
test cases: 1 | 1 failed
assertions: 1 | 1 failed
Proposed Fix
- In both constructors, compute the tuple count, the component count, the element count and the byte count with overflow checks before the allocation, and throw (for example
std::overflow_error) when a count does not fit inusize. A constructor cannot return aResult<>, so an exception is the only way to reject the shape. - A shape that contains a zero dimension has a count of zero. Check for a zero dimension before the multiplication, so that a large partial product of the other dimensions is not reported as an overflow.
EmptyDataStore::CheckedPlaceholderProduct(src/simplnx/DataStructure/EmptyDataStore.hpp) already uses this approach. - Put the checked product in one helper that the constructors and
resizeTuples()share.
Notes
- PR #1834 adds the same tuple, element and byte overflow checks to
DataStore::resizeTuples(), with the zero-dimension rule above. The constructors are not part of that PR. StringStoreandListStorehave the same unchecked product inresizeTuples()(#1884). An allocation above the AddressSanitizer limit is reported in #1885.
- 主要言語
- C++
- スター
- 18
- フォーク
- 15
- 平均マージ
- 4日 23時間
- マージ済み PR(30日)
- 42
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
BlueQuartzSoftware/simplnx のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
BlueQuartzSoftware/simplnx#1987 ·
メンテナーはふだん 6 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
BlueQuartzSoftware/simplnx#1980 ·
メンテナーはふだん 6 日以内に返信
-
Testing
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
BlueQuartzSoftware/simplnx#1979 ·
メンテナーはふだん 6 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
BlueQuartzSoftware/simplnx#1978 ·
メンテナーはふだん 6 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
BlueQuartzSoftware/simplnx#1945 ·
メンテナーはふだん 6 日以内に返信
BlueQuartzSoftware/simplnx の issue をすべて見る
似ている issue
-
bug triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
26.04 bug dark-mode Easy Hack impress symptom: visual
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
CollaboraOnline/online#16421 · コメント 1 件 ·
-
area/cs bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
ydb-platform/ydb#59881 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
documentation enhancement lua server
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100