BUG: DataStore constructors accept a tuple shape whose product overflows
I maintainer di solito rispondono entro 6 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 54/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C++
- Stelle
- 18
- Fork
- 15
- Merge medio
- 4g 23h
- PR unite (30g)
- 42
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di BlueQuartzSoftware/simplnx
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
BlueQuartzSoftware/simplnx#1987 ·
I maintainer di solito rispondono entro 6 giorni
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
BlueQuartzSoftware/simplnx#1980 ·
I maintainer di solito rispondono entro 6 giorni
-
Testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
BlueQuartzSoftware/simplnx#1979 ·
I maintainer di solito rispondono entro 6 giorni
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
BlueQuartzSoftware/simplnx#1978 ·
I maintainer di solito rispondono entro 6 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
BlueQuartzSoftware/simplnx#1945 ·
I maintainer di solito rispondono entro 6 giorni
Tutte le issue di BlueQuartzSoftware/simplnx
Issue simili
-
bug triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
26.04 bug dark-mode Easy Hack impress symptom: visual
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
CollaboraOnline/online#16421 · 1 commento ·
-
area/cs bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ydb-platform/ydb#59881 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
documentation enhancement lua server
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100