Skip to content

Commit

Permalink
Check permutation size before calling reserve() in WaksmanPermuterFor…
Browse files Browse the repository at this point in the history
…BitString (#459)

Summary:
In T139444907 the NCC made us aware of the fact that an array of size 1 would cause the permuter to throw and exception. This is due to the bit size calculation for a single value permutation to return -1 as the required size.

Pull Request resolved: #459

Reviewed By: xyguo

Differential Revision: D42014844

fbshipit-source-id: 5f78009c9845204052b7c7f9da36518858aac839
  • Loading branch information
Tal Davidi authored and facebook-github-bot committed Jan 12, 2023
1 parent e576615 commit 3612374
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ AsWaksmanPermuter<std::vector<bool>, schedulerId>::permute(
}
auto length = vectorOfVectors.at(0).size();
std::vector<std::vector<bool>> rst;
rst.reserve(2 * (std::ceil(log2(order.size()))) - 1);
if (order.size() > 2) {
rst.reserve(2 * (std::ceil(log2(order.size()))) - 1);
}
computeChoiceVectors(
std::vector<std::vector<uint32_t>>(1, order), rst, order.size());

Expand Down
15 changes: 11 additions & 4 deletions fbpcf/mpc_std_lib/permuter/test/PermuterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ void party1Task(

void permuterTest(
IPermuterFactory<frontend::BitString<true, 0, true>>& permuterFactory0,
IPermuterFactory<frontend::BitString<true, 1, true>>& permuterFactory1) {
IPermuterFactory<frontend::BitString<true, 1, true>>& permuterFactory1,
uint32_t size) {
auto agentFactories = engine::communication::getInMemoryAgentFactory(2);
setupRealBackend<0, 1>(*agentFactories[0], *agentFactories[1]);
auto permuter0 = permuterFactory0.create();
auto permuter1 = permuterFactory1.create();
uint32_t size = 17;
auto [originalData, order, expectedOutput] = getPermuterTestData(size);
auto future0 =
std::async(party0Task, std::move(permuter0), originalData, order);
Expand All @@ -95,14 +95,21 @@ TEST(permuterTest, testDummyPermuter) {
insecure::DummyPermuterFactory<std::vector<bool>, 0> factory0(0, 1);
insecure::DummyPermuterFactory<std::vector<bool>, 1> factory1(1, 0);

permuterTest(factory0, factory1);
permuterTest(factory0, factory1, 17);
}

TEST(permuterTest, testAsWaksmanPermuter) {
AsWaksmanPermuterFactory<std::vector<bool>, 0> factory0(0, 1);
AsWaksmanPermuterFactory<std::vector<bool>, 1> factory1(1, 0);

permuterTest(factory0, factory1);
permuterTest(factory0, factory1, 17);
}

TEST(permuterTest, testAsWaksmanPermuterSingleValue) {
AsWaksmanPermuterFactory<std::vector<bool>, 0> factory0(0, 1);
AsWaksmanPermuterFactory<std::vector<bool>, 1> factory1(1, 0);

permuterTest(factory0, factory1, 1);
}

void testAsWaksmanParameter() {
Expand Down

0 comments on commit 3612374

Please sign in to comment.