From 1a4ce5ec8eca43f876e6401d11794558bfab4662 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Sun, 11 Apr 2021 09:52:17 +0100 Subject: [PATCH] Fixed newline in CURRENT file (#6) --- db/version_set.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/db/version_set.cc b/db/version_set.cc index 2d1cd12a..9aea2957 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -917,13 +917,16 @@ Status VersionSet::Recover(bool *save_manifest) { return s; } const size_t size = current.size(); - if (size == 0 || (current[size - 1] != '\n' && current[size - 1] != '\r')) { - return Status::Corruption("CURRENT file does not end with newline"); - } - - int resizeSize = 1; - if (size >= 2 && current[size - 2] == '\r') { - resizeSize = 2; + if (size == 0) { + return Status::Corruption("CURRENT file is empty"); + } + + int resizeSize = 0; + while (current[size - resizeSize - 1] == '\n' || current[size - resizeSize - 1] == '\r') { + resizeSize += 1; + if (size <= resizeSize) { + return Status::Corruption("CURRENT file is empty"); + } } current.resize(size - resizeSize);