From: Jon Bailey Date: Thu, 13 Feb 2025 11:22:30 +0000 (+0000) Subject: erasure-code: Add extra checks to gracefully fail when invalid values are supplied... X-Git-Tag: testing/wip-vshankar-testing-20250407.170244-debug~21^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=3a1106c5a49415c33b270cc807b4602d578aacd7;p=ceph-ci.git erasure-code: Add extra checks to gracefully fail when invalid values are supplied in erasure code profiles Signed-off-by: Jon Bailey --- diff --git a/src/erasure-code/ErasureCode.cc b/src/erasure-code/ErasureCode.cc index 6bf965af809..6640acdbc71 100644 --- a/src/erasure-code/ErasureCode.cc +++ b/src/erasure-code/ErasureCode.cc @@ -111,6 +111,11 @@ int ErasureCode::sanity_check_k_m(int k, int m, ostream *ss) *ss << "m=" << m << " must be >= 1" << std::endl; return -EINVAL; } + int max_k_plus_m = std::numeric_limits::max(); + if (k+m > max_k_plus_m) { + *ss << "(k+m)=" << (k+m) << " must be <= " << max_k_plus_m << std::endl; + return -EINVAL; + } return 0; } diff --git a/src/erasure-code/isa/ErasureCodeIsa.cc b/src/erasure-code/isa/ErasureCodeIsa.cc index b2bbff572a0..b6a02a3d66e 100644 --- a/src/erasure-code/isa/ErasureCodeIsa.cc +++ b/src/erasure-code/isa/ErasureCodeIsa.cc @@ -217,8 +217,7 @@ ErasureCodeIsaDefault::apply_delta(const shard_id_map &in, data[1] = const_cast(codingbuf.c_str()); char * coding = const_cast(codingbuf.c_str()); isa_xor(data, coding, blocksize, data_vectors); - } - else { + } else { unsigned char* data = reinterpret_cast(const_cast(databuf.c_str())); unsigned char* coding = reinterpret_cast(const_cast(codingbuf.c_str())); ec_encode_data_update(blocksize, k, 1, static_cast(datashard), encode_tbls + (32 * k * (static_cast(codingshard) - k)), data, &coding); @@ -429,14 +428,22 @@ int ErasureCodeIsaDefault::parse(ErasureCodeProfile &profile, err |= to_int("m", profile, &m, DEFAULT_M, ss); err |= sanity_check_k_m(k, m, ss); + if (m > MAX_M) { + *ss << "isa: m=" << m << " should be less/equal than " << MAX_M + << " : revert to m=" << MAX_M << std::endl; + m = MAX_M; + err = -EINVAL; + } + if (matrixtype == kVandermonde) { // these are verified safe values evaluated using the // benchmarktool and 10*(combinatoric for maximum loss) random // full erasures - if (k > 32) { + if (k > MAX_K) { *ss << "Vandermonde: m=" << m - << " should be less/equal than 32 : revert to k=32" << std::endl; - k = 32; + << " should be less/equal than " << MAX_K + << " : revert to k=" << MAX_K << std::endl; + k = MAX_K; err = -EINVAL; } diff --git a/src/erasure-code/isa/ErasureCodeIsa.h b/src/erasure-code/isa/ErasureCodeIsa.h index eb39b1d3ed0..3ffc1845841 100644 --- a/src/erasure-code/isa/ErasureCodeIsa.h +++ b/src/erasure-code/isa/ErasureCodeIsa.h @@ -43,6 +43,7 @@ public: }; static constexpr int MAX_K = 32; + static constexpr int MAX_M = 32; int k; int m;