From: Kefu Chai Date: Sun, 20 Dec 2020 05:02:46 +0000 (+0800) Subject: erasure-code: bail out early if chunks to be decoded is empty X-Git-Tag: v16.1.0~173^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=98e2be7f75f59ec6fbfb99e4e0b39db76a94127e;p=ceph.git erasure-code: bail out early if chunks to be decoded is empty 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 --- diff --git a/src/erasure-code/shec/ErasureCodeShec.cc b/src/erasure-code/shec/ErasureCodeShec.cc index 03a1d23f9a9c..3634be2fb3b9 100644 --- a/src/erasure-code/shec/ErasureCodeShec.cc +++ b/src/erasure-code/shec/ErasureCodeShec.cc @@ -179,6 +179,10 @@ int ErasureCodeShec::_decode(const set &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::const_iterator i = chunks.begin(); diff --git a/src/test/erasure-code/TestErasureCodeShec_arguments.cc b/src/test/erasure-code/TestErasureCodeShec_arguments.cc index 52684faac909..561afafa6cd2 100644 --- a/src/test/erasure-code/TestErasureCodeShec_arguments.cc +++ b/src/test/erasure-code/TestErasureCodeShec_arguments.cc @@ -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; }