openfheorg / openfhe-development

This is the development repository for the OpenFHE library. The current (stable) version is v1.2.1 (released on September 10, 2024).
BSD 2-Clause "Simplified" License
724 stars 188 forks source link

s_evalAutomorphismKeyMap gets an extra index of zero due to vector initialization #783

Closed evmanz closed 4 months ago

evmanz commented 4 months ago

The GetExistingEvalAutomorphismKeyIndices(...) method in src/pke/lib/cryptocontext.cpp adds extra index with value of zero to the vector of key indices from the KeyMap.

It happens because the vector first is set to specific size with all values set to default value of 0:

std::vector<uint32_t> indices(keyMap.size()); and then existing indices in the map are push_back(...)'ed to it.

As a result, the vector of indices has 0s inside which are not present in the original map, and thus have no actual key behind them (an empty PolyImpl is created later).

As a result, there is a segfault due to a null pointer dereference in CompressEvalKeys(...) function in demo-logistic.cpp: CompressEvalKeys(...).