Skip to content

Commit

Permalink
Merge pull request #348 from Laupetin/fix/t6-long-fastfile-names
Browse files Browse the repository at this point in the history
fix: long fastfile names
  • Loading branch information
Laupetin authored Jan 15, 2025
2 parents a1d3e64 + 85d9f1c commit 64bac44
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/ZoneCommon/Zone/XChunk/AbstractSalsa20Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ uint8_t* AbstractSalsa20Processor::GetHashBlock(const int streamNumber) const

void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize) const
{
const auto zoneNameLength = zoneName.length();
// Original buffer must have been 32 bytes because the zoneName can at most be 31 characters be long before being cut off
const auto zoneNameLength = std::min(zoneName.length(), 31u);

const size_t blockHashBufferSize = BLOCK_HASHES_COUNT * m_stream_count * SHA1_HASH_SIZE;

assert(blockHashBufferSize % 4 == 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "InvalidFileNameException.h"

InvalidFileNameException::InvalidFileNameException(std::string& actualFileName, std::string& expectedFileName)
#include <format>

InvalidFileNameException::InvalidFileNameException(const std::string& actualFileName, const std::string& expectedFileName)
{
m_actual_file_name = actualFileName;
m_expected_file_name = expectedFileName;
}

std::string InvalidFileNameException::DetailedMessage()
{
return "Name verification failed: The fastfile was created as '" + m_expected_file_name + "' but loaded as '" + m_actual_file_name + "'";
return std::format("Name verification failed: The fastfile was created as '{}' but loaded as '{}'", m_expected_file_name, m_actual_file_name);
}

char const* InvalidFileNameException::what() const noexcept
Expand Down
8 changes: 4 additions & 4 deletions src/ZoneLoading/Loading/Exception/InvalidFileNameException.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

class InvalidFileNameException final : public LoadingException
{
std::string m_actual_file_name;
std::string m_expected_file_name;

public:
InvalidFileNameException(std::string& actualFileName, std::string& expectedFileName);
InvalidFileNameException(const std::string& actualFileName, const std::string& expectedFileName);

std::string DetailedMessage() override;
char const* what() const noexcept override;

std::string m_actual_file_name;
std::string m_expected_file_name;
};
13 changes: 6 additions & 7 deletions src/ZoneLoading/Loading/Steps/StepVerifyFileName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
#include <sstream>

StepVerifyFileName::StepVerifyFileName(std::string fileName, const size_t fileNameBufferSize)
: m_expected_file_name(std::move(fileName)),
m_file_name_buffer_size(fileNameBufferSize)
{
m_file_name = std::move(fileName);
m_file_name_buffer_size = fileNameBufferSize;

if (m_file_name.length() > m_file_name_buffer_size)
m_file_name.erase(m_file_name_buffer_size);
if (m_expected_file_name.length() > (m_file_name_buffer_size - 1))
m_expected_file_name.erase(m_file_name_buffer_size - 1);
}

void StepVerifyFileName::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
Expand Down Expand Up @@ -42,6 +41,6 @@ void StepVerifyFileName::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* str

std::string originalFileName = originalFilenameStream.str();

if (originalFileName != m_file_name)
throw InvalidFileNameException(m_file_name, originalFileName);
if (originalFileName != m_expected_file_name)
throw InvalidFileNameException(m_expected_file_name, originalFileName);
}
2 changes: 1 addition & 1 deletion src/ZoneLoading/Loading/Steps/StepVerifyFileName.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class StepVerifyFileName final : public ILoadingStep
{
std::string m_file_name;
std::string m_expected_file_name;
size_t m_file_name_buffer_size;

public:
Expand Down

0 comments on commit 64bac44

Please sign in to comment.