From 867d5c962d92d6b40f67b6e55c3ccff0e1183ed6 Mon Sep 17 00:00:00 2001 From: Or Ozeri Date: Thu, 24 Dec 2020 11:24:40 +0200 Subject: [PATCH] librbd: fix crypto handling of empty reads This commit ensures correct handling of empty bufferlists returned by librados object read Signed-off-by: Or Ozeri --- src/librbd/crypto/CryptoInterface.h | 2 +- src/librbd/crypto/CryptoObjectDispatch.cc | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/librbd/crypto/CryptoInterface.h b/src/librbd/crypto/CryptoInterface.h index 29e205188fe..8b1f57924b1 100644 --- a/src/librbd/crypto/CryptoInterface.h +++ b/src/librbd/crypto/CryptoInterface.h @@ -60,7 +60,7 @@ public: inline int decrypt_aligned_extent(io::ReadExtent& extent, uint64_t image_offset) { - if (extent.length == 0) { + if (extent.length == 0 || extent.bl.length() == 0) { return 0; } diff --git a/src/librbd/crypto/CryptoObjectDispatch.cc b/src/librbd/crypto/CryptoObjectDispatch.cc index b82cd679f76..2c5f9b37019 100644 --- a/src/librbd/crypto/CryptoObjectDispatch.cc +++ b/src/librbd/crypto/CryptoObjectDispatch.cc @@ -132,8 +132,13 @@ struct C_UnalignedObjectReadRequest : public Context { auto& extent = (*extents)[i]; auto& aligned_extent = aligned_extents[i]; if (aligned_extent.extent_map.empty()) { - aligned_extent.bl.splice(extent.offset - aligned_extent.offset, - extent.length, &extent.bl); + uint64_t cut_offset = extent.offset - aligned_extent.offset; + int64_t padding_count = + cut_offset + extent.length - aligned_extent.bl.length(); + if (padding_count > 0) { + aligned_extent.bl.append_zero(padding_count); + } + aligned_extent.bl.splice(cut_offset, extent.length, &extent.bl); } else { for (auto [off, len]: aligned_extent.extent_map) { ceph::bufferlist tmp; -- 2.39.5