From 8c694025e9ddcfac4ce8aa39dbf51577d8e4d470 Mon Sep 17 00:00:00 2001 From: Zhichao Cao Date: Thu, 30 Apr 2020 08:38:18 -0700 Subject: [PATCH] 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 --- db/import_column_family_job.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/import_column_family_job.cc b/db/import_column_family_job.cc index e9b53f465..4b0502c49 100644 --- a/db/import_column_family_job.cc +++ b/db/import_column_family_job.cc @@ -62,7 +62,7 @@ Status ImportColumnFamilyJob::Prepare(uint64_t next_file_number, 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( sorted_files[i]->largest_internal_key, sorted_files[i + 1]->smallest_internal_key) >= 0) {