From 551c462467bf611d4ba4546f8b75325ea62e9a93 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 27 Apr 2021 11:57:40 +0900 Subject: [PATCH] add comment Fp::load --- include/mcl/fp.hpp | 3 ++- test/fp_test.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index b85b691..c52ce78 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -264,6 +264,7 @@ public: { if (isMont()) op_.fromMont(v_, v_); } + // deny a string with large length even if the value is in Fp template void load(bool *pb, InputStream& is, int ioMode) { @@ -283,7 +284,7 @@ public: } if (readSize != n) return; } else { - char buf[1024]; + char buf[sizeof(*this) * 8 + 2]; // '0b' + max binary format length size_t n = fp::local::loadWord(buf, sizeof(buf), is); if (n == 0) return; n = fp::strToArray(&isMinus, v_, op_.N, buf, n, ioMode); diff --git a/test/fp_test.cpp b/test/fp_test.cpp index 41ce7a0..3f15a0d 100644 --- a/test/fp_test.cpp +++ b/test/fp_test.cpp @@ -105,6 +105,15 @@ void setStrTest() CYBOZU_TEST_EXCEPTION(x.setStr("0b100", 10), cybozu::Exception); CYBOZU_TEST_EXCEPTION(x.setStr("0x100", 2), cybozu::Exception); CYBOZU_TEST_EXCEPTION(x.setStr("0x100", 10), cybozu::Exception); + + x = 1; + std::string s; + s.resize(Fp::getOp().N * mcl::fp::UnitBitSize, '0'); + s = "0b" + s; + x.setStr(s, 2); + CYBOZU_TEST_ASSERT(x.isZero()); + s += '0'; + CYBOZU_TEST_EXCEPTION(x.setStr(s, 2), cybozu::Exception); } }