Skip to content

Commit 54b4582

Browse files
committed
compressor/zstd: correct buffer end detection using get_remaining()
Replace p.end() check with get_remaining() to properly detect buffer exhaustion. The source bufferlist may contain empty pointers at the end, causing p.end() to return false even when all data has been processed during compression. Signed-off-by: Igor Fedotov <[email protected]>
1 parent 407e9b7 commit 54b4582

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
@@ -51,7 +51,7 @@ class ZstdCompressor : public Compressor {
5151
return -EINVAL;
5252
}
5353
}
54-
ceph_assert(p.end());
54+
ceph_assert(p.get_remaining() == 0);
5555

5656
ZSTD_freeCStream(s);
5757

src/test/compressor/test_compression.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,14 @@ TEST_P(CompressorTest, compress_decompress)
213213
bufferlist in, out;
214214
bufferlist after;
215215
bufferlist exp;
216+
216217
in.append(test, len);
218+
exp.append(test);
217219
std::optional<int32_t> compressor_message;
218220
res = compressor->compress(in, out, compressor_message);
219221
EXPECT_EQ(res, 0);
220222
res = compressor->decompress(out, after, compressor_message);
221223
EXPECT_EQ(res, 0);
222-
exp.append(test);
223224
EXPECT_TRUE(exp.contents_equal(after));
224225
after.clear();
225226
size_t compressed_len = out.length();
@@ -229,6 +230,25 @@ TEST_P(CompressorTest, compress_decompress)
229230
EXPECT_EQ(res, 0);
230231
EXPECT_TRUE(exp.contents_equal(after));
231232

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

0 commit comments

Comments
 (0)