Skip to content

Commit

Permalink
Added better CURRENT file handling (#9)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gentlegiantJGC authored Oct 5, 2022
1 parent 45aa1a8 commit 327630b
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 327630b

Please sign in to comment.