From 98e2be7f75f59ec6fbfb99e4e0b39db76a94127e Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 20 Dec 2020 13:02:46 +0800 Subject: [PATCH] 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 --- src/erasure-code/shec/ErasureCodeShec.cc | 4 ++++ src/test/erasure-code/TestErasureCodeShec_arguments.cc | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/erasure-code/shec/ErasureCodeShec.cc b/src/erasure-code/shec/ErasureCodeShec.cc index 03a1d23f9a9..3634be2fb3b 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 52684faac90..561afafa6cd 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; } -- 2.39.5