From ef9189479848c872a1443b9ea6ef126544a48978 Mon Sep 17 00:00:00 2001 From: sdong Date: Wed, 18 Dec 2019 17:02:39 -0800 Subject: [PATCH] Fix potential overflow in CalculateSSTWriteHint() (#6212) Summary: level passed into ColumnFamilyData::CalculateSSTWriteHint() can be smaller than base_level in current version, which would cause overflow. We see ubsan complains: db/compaction/compaction_job.cc:1511:39: runtime error: load of value 4294967295, which is not a valid value for type 'Env::WriteLifeTimeHint' and I hope this commit fixes it. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6212 Test Plan: Run existing tests and see them to pass. Differential Revision: D19168442 fbshipit-source-id: bf8fd86f85478ecfa7556db46dc3242de8c83dc9 --- db/column_family.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/db/column_family.cc b/db/column_family.cc index 290283608..1611125cd 100644 --- a/db/column_family.cc +++ b/db/column_family.cc @@ -1306,6 +1306,10 @@ Env::WriteLifeTimeHint ColumnFamilyData::CalculateSSTWriteHint(int level) { // L1: medium, L2: long, ... if (level - base_level >= 2) { return Env::WLTH_EXTREME; + } else if (level < base_level) { + // There is no restriction which prevents level passed in to be smaller + // than base_level. + return Env::WLTH_MEDIUM; } return static_cast(level - base_level + static_cast(Env::WLTH_MEDIUM));