Skip to content

Commit cba051d

Browse files
committed
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 <[email protected]>
1 parent 6d42ff4 commit cba051d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/test/crimson/seastore/test_block.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ struct test_extent_desc_t {
2424

2525
struct test_block_delta_t {
2626
int8_t val = 0;
27-
uint16_t offset = 0;
28-
uint16_t len = 0;
27+
extent_len_t offset = 0;
28+
extent_len_t len = 0;
2929

3030

3131
DENC(test_block_delta_t, v, p) {
@@ -67,7 +67,9 @@ struct TestBlock : crimson::os::seastore::LogicalCachedExtent {
6767

6868
ceph::bufferlist get_delta() final;
6969

70-
void set_contents(char c, uint16_t offset, uint16_t len) {
70+
void set_contents(char c, extent_len_t offset, extent_len_t len) {
71+
assert(offset + len <= get_length());
72+
assert(len > 0);
7173
::memset(get_bptr().c_str() + offset, c, len);
7274
delta.push_back({c, offset, len});
7375
modified_region.union_insert(offset, len);
@@ -121,7 +123,7 @@ struct TestBlockPhysical : crimson::os::seastore::CachedExtent{
121123
return TYPE;
122124
}
123125

124-
void set_contents(char c, uint16_t offset, uint16_t len) {
126+
void set_contents(char c, extent_len_t offset, extent_len_t len) {
125127
::memset(get_bptr().c_str() + offset, c, len);
126128
delta.push_back({c, offset, len});
127129
}
@@ -142,13 +144,13 @@ struct test_block_mutator_t {
142144
std::numeric_limits<int8_t>::min(),
143145
std::numeric_limits<int8_t>::max());
144146

145-
std::uniform_int_distribution<uint16_t>
146-
offset_distribution = std::uniform_int_distribution<uint16_t>(
147+
std::uniform_int_distribution<extent_len_t>
148+
offset_distribution = std::uniform_int_distribution<extent_len_t>(
147149
0, TestBlock::SIZE - 1);
148150

149-
std::uniform_int_distribution<uint16_t> length_distribution(uint16_t offset) {
150-
return std::uniform_int_distribution<uint16_t>(
151-
0, TestBlock::SIZE - offset - 1);
151+
std::uniform_int_distribution<extent_len_t> length_distribution(extent_len_t offset) {
152+
return std::uniform_int_distribution<extent_len_t>(
153+
1, TestBlock::SIZE - offset);
152154
}
153155

154156

0 commit comments

Comments
 (0)