]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
erasure-code: Add extra checks to gracefully fail when invalid values are supplied...
authorJon Bailey <jonathan.bailey1@ibm.com>
Thu, 13 Feb 2025 11:22:30 +0000 (11:22 +0000)
committerAlex Ainscow <aainscow@uk.ibm.com>
Wed, 19 Mar 2025 11:03:56 +0000 (11:03 +0000)
Signed-off-by: Jon Bailey <jonathan.bailey1@ibm.com>
src/erasure-code/ErasureCode.cc
src/erasure-code/isa/ErasureCodeIsa.cc
src/erasure-code/isa/ErasureCodeIsa.h

index 6bf965af8092fda9e2c5582ea4228f77e2df3203..6640acdbc7156ca53a372bc46221400887b02d6f 100644 (file)
@@ -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<decltype(shard_id_t::id)>::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;
 }
 
index b2bbff572a0cbc510b1fe559de7c004cf15898ab..b6a02a3d66e7e3fbac72445b0384876be96a3cd4 100644 (file)
@@ -217,8 +217,7 @@ ErasureCodeIsaDefault::apply_delta(const shard_id_map<bufferptr> &in,
             data[1] = const_cast<char*>(codingbuf.c_str());
             char * coding = const_cast<char*>(codingbuf.c_str());
             isa_xor(data, coding, blocksize, data_vectors);
-          }
-          else {
+          } else {
             unsigned char* data = reinterpret_cast<unsigned char*>(const_cast<char*>(databuf.c_str()));
             unsigned char* coding = reinterpret_cast<unsigned char*>(const_cast<char*>(codingbuf.c_str()));
             ec_encode_data_update(blocksize, k, 1, static_cast<int>(datashard), encode_tbls + (32 * k * (static_cast<int>(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;
     }
 
index eb39b1d3ed05a199f0699241f3f7ede45299da04..3ffc184584186feb96ee25e1527b8b28b83083df 100644 (file)
@@ -43,6 +43,7 @@ public:
   };
 
   static constexpr int MAX_K = 32;
+  static constexpr int MAX_M = 32;
 
   int k;
   int m;