Fix potential size_t overflow in import_column_family (#6762)

Summary:
The issue is reported in https://github.com/facebook/rocksdb/issues/6753 . size_t is unsigned and if sorted_file.size() is 0, the end condition of i will be extremely large, cause segment fault in sorted_files[i] and sorted_files[i+1]. Added condition to fix it.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6762

Test Plan: make asan_check

Reviewed By: pdillinger

Differential Revision: D21323063

Pulled By: zhichao-cao

fbshipit-source-id: 56ce59201949ed319448228553202b8642c2cc3a
main
Zhichao Cao 5 years ago committed by Facebook GitHub Bot
parent b938e6042b
commit 8c694025e9
  1. 2
      db/import_column_family_job.cc

@ -62,7 +62,7 @@ Status ImportColumnFamilyJob::Prepare(uint64_t next_file_number,
info2->smallest_internal_key) < 0; info2->smallest_internal_key) < 0;
}); });
for (size_t i = 0; i < sorted_files.size() - 1; i++) { for (size_t i = 0; i + 1 < sorted_files.size(); i++) {
if (cfd_->internal_comparator().Compare( if (cfd_->internal_comparator().Compare(
sorted_files[i]->largest_internal_key, sorted_files[i]->largest_internal_key,
sorted_files[i + 1]->smallest_internal_key) >= 0) { sorted_files[i + 1]->smallest_internal_key) >= 0) {

Loading…
Cancel
Save