Skip to content

Commit a2c3957

Browse files
authored
Merge pull request ceph#64682 from ifed01/wip-ifed-fix-zstd
compressor/zstd: compressor correct buffer end detection using get_remaining() Reviewed-by: Kefu Chai <[email protected]>
2 parents 353eaff + 54b4582 commit a2c3957

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/compressor/zstd/ZstdCompressor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ZstdCompressor : public Compressor {
5252
return -EINVAL;
5353
}
5454
}
55-
ceph_assert(p.end());
55+
ceph_assert(p.get_remaining() == 0);
5656

5757
ZSTD_freeCStream(s);
5858

src/test/compressor/test_compression.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,14 @@ TEST_P(CompressorTest, compress_decompress)
214214
bufferlist in, out;
215215
bufferlist after;
216216
bufferlist exp;
217+
217218
in.append(test, len);
219+
exp.append(test);
218220
std::optional<int32_t> compressor_message;
219221
res = compressor->compress(in, out, compressor_message);
220222
EXPECT_EQ(res, 0);
221223
res = compressor->decompress(out, after, compressor_message);
222224
EXPECT_EQ(res, 0);
223-
exp.append(test);
224225
EXPECT_TRUE(exp.contents_equal(after));
225226
after.clear();
226227
size_t compressed_len = out.length();
@@ -230,6 +231,25 @@ TEST_P(CompressorTest, compress_decompress)
230231
EXPECT_EQ(res, 0);
231232
EXPECT_TRUE(exp.contents_equal(after));
232233

234+
//compressing bl which has got empty bufferptr at the end
235+
in.clear();
236+
out.clear();
237+
after.clear();
238+
exp.clear();
239+
240+
const size_t PREALLOC_SIZE = 1; // any non-zero value would suffice here
241+
bufferlist dummy(PREALLOC_SIZE); // this appends an empty preallocated ptr to the end of the bufferlist
242+
EXPECT_TRUE(dummy.buffers().back().length() == 0); // make sure we have empty ptr at the end
243+
in.append(test, len);
244+
in.append(dummy);
245+
exp.append(test);
246+
247+
res = compressor->compress(in, out, compressor_message);
248+
EXPECT_EQ(res, 0);
249+
res = compressor->decompress(out, after, compressor_message);
250+
EXPECT_EQ(res, 0);
251+
EXPECT_TRUE(exp.contents_equal(after));
252+
233253
//large block and non-begin iterator for continuous block
234254
std::string data;
235255
data.resize(0x10000 * 1);

0 commit comments

Comments
 (0)