Skip to content

Commit 3a1106c

Browse files
JonBailey1993aainscow
authored andcommitted
erasure-code: Add extra checks to gracefully fail when invalid values are supplied in erasure code profiles
Signed-off-by: Jon Bailey <[email protected]>
1 parent bf2e074 commit 3a1106c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/erasure-code/ErasureCode.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ int ErasureCode::sanity_check_k_m(int k, int m, ostream *ss)
111111
*ss << "m=" << m << " must be >= 1" << std::endl;
112112
return -EINVAL;
113113
}
114+
int max_k_plus_m = std::numeric_limits<decltype(shard_id_t::id)>::max();
115+
if (k+m > max_k_plus_m) {
116+
*ss << "(k+m)=" << (k+m) << " must be <= " << max_k_plus_m << std::endl;
117+
return -EINVAL;
118+
}
114119
return 0;
115120
}
116121

src/erasure-code/isa/ErasureCodeIsa.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ ErasureCodeIsaDefault::apply_delta(const shard_id_map<bufferptr> &in,
217217
data[1] = const_cast<char*>(codingbuf.c_str());
218218
char * coding = const_cast<char*>(codingbuf.c_str());
219219
isa_xor(data, coding, blocksize, data_vectors);
220-
}
221-
else {
220+
} else {
222221
unsigned char* data = reinterpret_cast<unsigned char*>(const_cast<char*>(databuf.c_str()));
223222
unsigned char* coding = reinterpret_cast<unsigned char*>(const_cast<char*>(codingbuf.c_str()));
224223
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,
429428
err |= to_int("m", profile, &m, DEFAULT_M, ss);
430429
err |= sanity_check_k_m(k, m, ss);
431430

431+
if (m > MAX_M) {
432+
*ss << "isa: m=" << m << " should be less/equal than " << MAX_M
433+
<< " : revert to m=" << MAX_M << std::endl;
434+
m = MAX_M;
435+
err = -EINVAL;
436+
}
437+
432438
if (matrixtype == kVandermonde) {
433439
// these are verified safe values evaluated using the
434440
// benchmarktool and 10*(combinatoric for maximum loss) random
435441
// full erasures
436-
if (k > 32) {
442+
if (k > MAX_K) {
437443
*ss << "Vandermonde: m=" << m
438-
<< " should be less/equal than 32 : revert to k=32" << std::endl;
439-
k = 32;
444+
<< " should be less/equal than " << MAX_K
445+
<< " : revert to k=" << MAX_K << std::endl;
446+
k = MAX_K;
440447
err = -EINVAL;
441448
}
442449

src/erasure-code/isa/ErasureCodeIsa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ErasureCodeIsa : public ceph::ErasureCode {
4343
};
4444

4545
static constexpr int MAX_K = 32;
46+
static constexpr int MAX_M = 32;
4647

4748
int k;
4849
int m;

0 commit comments

Comments
 (0)