From cba051d6e0d964ae3bc7337aee942ee91b9c663e Mon Sep 17 00:00:00 2001 From: Myoungwon Oh Date: Sun, 17 Dec 2023 18:04:10 +0900 Subject: [PATCH] test/crimson/seastore: fix overflow issue and make len > 0 when set_contents is called set_contents causes the overflow at times because alloc_extent is allowed to use uint32_t. Specifically, in random_writes case, PADDING_SIZE is 256<<10, whereas set_contents's len is uint16_t. Signed-off-by: Myoungwon Oh --- src/test/crimson/seastore/test_block.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/test/crimson/seastore/test_block.h b/src/test/crimson/seastore/test_block.h index 2c70b7dbb87..3bf119f7726 100644 --- a/src/test/crimson/seastore/test_block.h +++ b/src/test/crimson/seastore/test_block.h @@ -24,8 +24,8 @@ struct test_extent_desc_t { struct test_block_delta_t { int8_t val = 0; - uint16_t offset = 0; - uint16_t len = 0; + extent_len_t offset = 0; + extent_len_t len = 0; DENC(test_block_delta_t, v, p) { @@ -67,7 +67,9 @@ struct TestBlock : crimson::os::seastore::LogicalCachedExtent { ceph::bufferlist get_delta() final; - void set_contents(char c, uint16_t offset, uint16_t len) { + void set_contents(char c, extent_len_t offset, extent_len_t len) { + assert(offset + len <= get_length()); + assert(len > 0); ::memset(get_bptr().c_str() + offset, c, len); delta.push_back({c, offset, len}); modified_region.union_insert(offset, len); @@ -121,7 +123,7 @@ struct TestBlockPhysical : crimson::os::seastore::CachedExtent{ return TYPE; } - void set_contents(char c, uint16_t offset, uint16_t len) { + void set_contents(char c, extent_len_t offset, extent_len_t len) { ::memset(get_bptr().c_str() + offset, c, len); delta.push_back({c, offset, len}); } @@ -142,13 +144,13 @@ struct test_block_mutator_t { std::numeric_limits::min(), std::numeric_limits::max()); - std::uniform_int_distribution - offset_distribution = std::uniform_int_distribution( + std::uniform_int_distribution + offset_distribution = std::uniform_int_distribution( 0, TestBlock::SIZE - 1); - std::uniform_int_distribution length_distribution(uint16_t offset) { - return std::uniform_int_distribution( - 0, TestBlock::SIZE - offset - 1); + std::uniform_int_distribution length_distribution(extent_len_t offset) { + return std::uniform_int_distribution( + 1, TestBlock::SIZE - offset); } -- 2.39.5