From 084dc73b91c65e84db83b4bd94e79b1437c88834 Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Mon, 17 May 2021 11:27:21 +0100 Subject: [PATCH] Fast path for unformatted calls. --- code/Common/DefaultLogger.cpp | 39 ++++++++++---------- include/assimp/Logger.hpp | 69 +++++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 43 deletions(-) diff --git a/code/Common/DefaultLogger.cpp b/code/Common/DefaultLogger.cpp index 913857f85..4fa9c865b 100644 --- a/code/Common/DefaultLogger.cpp +++ b/code/Common/DefaultLogger.cpp @@ -163,55 +163,54 @@ Logger *DefaultLogger::create(const char *name /*= "AssimpLog.txt"*/, } // ---------------------------------------------------------------------------------- -void Logger::debugInternal(Assimp::Formatter::format f) { - std::string message = f; +void Logger::debug(const char *message) { + // SECURITY FIX: otherwise it's easy to produce overruns since // sometimes importers will include data from the input file // (i.e. node names) in their messages. - if (message.length() > MAX_LOG_MESSAGE_LENGTH) { + if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) { return; } - return OnDebug(message.c_str()); + return OnDebug(message); } // ---------------------------------------------------------------------------------- -void Logger::verboseDebugInternal(Assimp::Formatter::format f) { - std::string message = f; +void Logger::verboseDebug(const char *message) { + // SECURITY FIX: see above - if (message.length() > MAX_LOG_MESSAGE_LENGTH) { + if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) { return; } - return OnVerboseDebug(message.c_str()); + return OnVerboseDebug(message); } // ---------------------------------------------------------------------------------- -void Logger::infoInternal(Assimp::Formatter::format f) { - std::string message = f; +void Logger::info(const char *message) { + // SECURITY FIX: see above - if (message.length() > MAX_LOG_MESSAGE_LENGTH) { + if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) { return; } - return OnInfo(message.c_str()); + return OnInfo(message); } // ---------------------------------------------------------------------------------- -void Logger::warnInternal(Assimp::Formatter::format f) { - std::string message = f; +void Logger::warn(const char *message) { + // SECURITY FIX: see above - if (message.length() > MAX_LOG_MESSAGE_LENGTH) { + if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) { return; } - return OnWarn(message.c_str()); + return OnWarn(message); } // ---------------------------------------------------------------------------------- -void Logger::errorInternal(Assimp::Formatter::format f) { - std::string message = f; +void Logger::error(const char *message) { // SECURITY FIX: see above - if (message.length() > MAX_LOG_MESSAGE_LENGTH) { + if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) { return; } - return OnError(message.c_str()); + return OnError(message); } // ---------------------------------------------------------------------------------- diff --git a/include/assimp/Logger.hpp b/include/assimp/Logger.hpp index ecbd9df9b..cb9ef3770 100644 --- a/include/assimp/Logger.hpp +++ b/include/assimp/Logger.hpp @@ -101,41 +101,51 @@ public: // ---------------------------------------------------------------------- /** @brief Writes a info message * @param message Info message*/ + void debug(const char* message); + template void debug(T&&... args) { - debugInternal(Assimp::Formatter::format(), std::forward(args)...); + debugFormat(Assimp::Formatter::format(), std::forward(args)...); } // ---------------------------------------------------------------------- /** @brief Writes a debug message * @param message Debug message*/ + void verboseDebug(const char* message); + template void verboseDebug(T&&... args) { - verboseDebugInternal(Assimp::Formatter::format(), std::forward(args)...); + verboseDebugFormat(Assimp::Formatter::format(), std::forward(args)...); } // ---------------------------------------------------------------------- /** @brief Writes a info message * @param message Info message*/ + void info(const char* message); + template void info(T&&... args) { - infoInternal(Assimp::Formatter::format(), std::forward(args)...); + infoFormat(Assimp::Formatter::format(), std::forward(args)...); } // ---------------------------------------------------------------------- /** @brief Writes a warning message * @param message Warn message*/ + void warn(const char* message); + template void warn(T&&... args) { - warnInternal(Assimp::Formatter::format(), std::forward(args)...); + warnFormat(Assimp::Formatter::format(), std::forward(args)...); } // ---------------------------------------------------------------------- /** @brief Writes an error message * @param message Info message*/ + void error(const char* message); + template void error(T&&... args) { - errorInternal(Assimp::Formatter::format(), std::forward(args)...); + errorFormat(Assimp::Formatter::format(), std::forward(args)...); } // ---------------------------------------------------------------------- @@ -236,36 +246,49 @@ protected: virtual void OnError(const char* message) = 0; protected: - - void debugInternal(Assimp::Formatter::format f); - void verboseDebugInternal(Assimp::Formatter::format f); - void warnInternal(Assimp::Formatter::format f); - void infoInternal(Assimp::Formatter::format f); - void errorInternal(Assimp::Formatter::format f); - - template - void debugInternal(Assimp::Formatter::format f, U&& u, T&&... args) { - debugInternal(std::move(f << std::forward(u)), std::forward(args)...); + void debugFormat(Assimp::Formatter::format f) { + debug(std::string(f).c_str()); } template - void verboseDebugInternal(Assimp::Formatter::format f, U&& u, T&&... args) { - verboseDebugInternal(std::move(f << std::forward(u)), std::forward(args)...); + void debugFormat(Assimp::Formatter::format f, U&& u, T&&... args) { + debugFormat(std::move(f << std::forward(u)), std::forward(args)...); + } + + void verboseDebugFormat(Assimp::Formatter::format f) { + verboseDebug(std::string(f).c_str()); } template - void warnInternal(Assimp::Formatter::format f, U&& u, T&&... args) { - warnInternal(std::move(f << std::forward(u)), std::forward(args)...); + void verboseDebugFormat(Assimp::Formatter::format f, U&& u, T&&... args) { + verboseDebugFormat(std::move(f << std::forward(u)), std::forward(args)...); + } + + void warnFormat(Assimp::Formatter::format f) { + warn(std::string(f).c_str()); } template - void infoInternal(Assimp::Formatter::format f, U&& u, T&&... args) { - infoInternal(std::move(f << std::forward(u)), std::forward(args)...); + void warnFormat(Assimp::Formatter::format f, U&& u, T&&... args) { + warnFormat(std::move(f << std::forward(u)), std::forward(args)...); + } + + void infoFormat(Assimp::Formatter::format f) { + info(std::string(f).c_str()); } template - void errorInternal(Assimp::Formatter::format f, U&& u, T&&... args) { - errorInternal(std::move(f << std::forward(u)), std::forward(args)...); + void infoFormat(Assimp::Formatter::format f, U&& u, T&&... args) { + infoFormat(std::move(f << std::forward(u)), std::forward(args)...); + } + + void errorFormat(Assimp::Formatter::format f) { + error(std::string(f).c_str()); + } + + template + void errorFormat(Assimp::Formatter::format f, U&& u, T&&... args) { + errorFormat(std::move(f << std::forward(u)), std::forward(args)...); } protected: