From 32de33be68f3892698d492b9ab8f21f9186b3f4c Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Wed, 2 Jun 2021 01:23:13 +0800 Subject: [PATCH 05/10] [thin_show_duplicates] Fix potential errors - Fix error if no --block-sector provided - Fix errors on pools without mappings, or zero-length file --- thin-provisioning/thin_show_duplicates.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/thin-provisioning/thin_show_duplicates.cc b/thin-provisioning/thin_show_duplicates.cc index b1eebb7..f7354eb 100644 --- a/thin-provisioning/thin_show_duplicates.cc +++ b/thin-provisioning/thin_show_duplicates.cc @@ -56,7 +56,7 @@ using namespace thin_provisioning; namespace { bool factor_of(block_address f, block_address n) { - return (n % f) == 0; + return f && (n % f) == 0; } uint64_t parse_int(string const &str, string const &desc) { @@ -132,11 +132,15 @@ namespace { class duplicate_detector { public: void scan_with_variable_sized_chunks(chunk_stream &stream) { + if (!stream.size()) + return; variable_chunk_stream vstream(stream, 4096); scan(vstream); } void scan_with_fixed_sized_chunks(chunk_stream &stream, block_address chunk_size) { + if (!stream.size()) + return; fixed_chunk_stream fstream(stream, chunk_size); scan(fstream); } @@ -222,7 +226,7 @@ namespace { if (fs.content_based_chunks) detector.scan_with_variable_sized_chunks(pstream); else { - if (*fs.block_size) { + if (!!fs.block_size) { if (factor_of(*fs.block_size, block_size)) block_size = *fs.block_size; else -- 1.8.3.1