From 327630b4ce17986963b80bf4dbcba32b19c13b88 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Wed, 5 Oct 2022 11:40:58 +0100 Subject: [PATCH] Added better CURRENT file handling (#9) Normal databases store the name of the manifest file in the CURRENT file. Marketplace worlds store some binary data in this file that seems to always start with a null character. The old code has been modified to extract the string up to a non-printable character. If the final result is an empty string a not supported status is returned. --- db/version_set.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/db/version_set.cc b/db/version_set.cc index 9aea295..45da2d6 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -916,20 +916,19 @@ Status VersionSet::Recover(bool *save_manifest) { if (!s.ok()) { return s; } - const size_t size = current.size(); + const size_t maxSize = current.size(); + size_t size = 0; + // find the first non-printable character (eg null, carriage return or newline) + for (size = 0; size < maxSize; size++){ + if (current[size] < 32) + break; + } + current.resize(size); if (size == 0) { + if (maxSize != 0) + return Status::NotSupported("CURRENT file did not contain a valid manifest name. Marketplace worlds are not supported."); 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); std::string dscname = dbname_ + "/" + current; SequentialFile* file;