]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
erasure-code: bail out early if chunks to be decoded is empty
authorKefu Chai <kchai@redhat.com>
Sun, 20 Dec 2020 05:02:46 +0000 (13:02 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 20 Dec 2020 17:26:46 +0000 (01:26 +0800)
otherwise we will read from uninitialized memory for blocksize.

update tests accordingly, as the number of decoded chunks is 0 if

* the number of available chunks is 0 and
* the number of requested chunks is not 0

after this change, because, in that case, the decode fails before any
chunk is allocated. but otherwise, the output chunks are still
allocated. so instead checking the number of output chunks, the test is
removed.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/erasure-code/shec/ErasureCodeShec.cc
src/test/erasure-code/TestErasureCodeShec_arguments.cc

index 03a1d23f9a9cb0149ae877599eb677666eb1c369..3634be2fb3b9d14a00ba5e222d3c1bf9d3699780 100644 (file)
@@ -179,6 +179,10 @@ int ErasureCodeShec::_decode(const set<int> &want_to_read,
   if (!decoded || !decoded->empty()){
     return -EINVAL;
   }
+  if (!want_to_read.empty() && chunks.empty()) {
+    // i need to get the blocksize from the first element of chunks
+    return -1;
+  }
 
   have.reserve(chunks.size());
   for (map<int, bufferlist>::const_iterator i = chunks.begin();
index 52684faac90946efac7e75ee7b40804f82985b46..561afafa6cd298d577347f706ba121c0dc98a468 100644 (file)
@@ -310,7 +310,6 @@ TEST(ParameterTest, combination_all)
               EXPECT_EQ(-EIO, result);
              EXPECT_EQ(0u, minimum_chunks.size());
               EXPECT_EQ(-1, dresult);
-              EXPECT_EQ(shec->get_chunk_count(), decoded.size());
               if (result != -EIO || dresult != -1) {
                 ++unexpected_count;
               }
@@ -346,7 +345,6 @@ TEST(ParameterTest, combination_all)
                 EXPECT_EQ(-EIO, result);
                EXPECT_EQ(0u, minimum_chunks.size());
                 EXPECT_EQ(-1, dresult);
-                EXPECT_EQ(shec->get_chunk_count(), decoded.size());
                 if (result != -EIO || dresult != -1) {
                   ++unexpected_count;
                 }