Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions app/app_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
#include <climits>
#include <cstdlib>
#include <limits>
#include "error.hpp"
#include "futils.hpp"

#if __has_include(<sys/resource.h>)
#include <sys/resource.h> // for getrlimit()
#define HAS_GETRLIMIT
#endif
Comment thread
kevinbackhouse marked this conversation as resolved.

namespace Util {
bool strtol(const char* nptr, int64_t& n) {
Expand All @@ -24,4 +31,31 @@ bool strtol(const char* nptr, int64_t& n) {
return true;
}

void increase_stack_limit() {
using namespace Exiv2;
#ifdef HAS_GETRLIMIT
{
struct rlimit rl {};

if (getrlimit(RLIMIT_STACK, &rl) < 0) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "getrlimit(RLIMIT_STACK) failed: " << strError() << "\n";
#endif
return;
}
if (rl.rlim_cur < rl.rlim_max) {
// Increase it to the max allowed.
rl.rlim_cur = rl.rlim_max;
if (setrlimit(RLIMIT_STACK, &rl) < 0) {
Comment thread
kevinbackhouse marked this conversation as resolved.
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "setrlimit(RLIMIT_STACK) failed: " << strError() << "\n";
#endif
return;
}
Comment thread
kevinbackhouse marked this conversation as resolved.
}
return;
}
#endif
}

} // namespace Util
7 changes: 7 additions & 0 deletions app/app_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace Util {
n is not modified if the conversion is unsuccessful. See strtol(2).
*/
bool strtol(const char* nptr, int64_t& n);

/*!
@brief This raises the default stack size limit so that deeply nested
files won't cause a crash. On Linux, the default stack size is
often only 8192KB, which is very easy to hit.
*/
void increase_stack_limit();
} // namespace Util

#endif // APP_UTILS_HPP_
1 change: 1 addition & 0 deletions app/exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ std::string parseEscapes(const std::string& input);
// Main
int main(int argc, char* const argv[]) {
setlocale(LC_CTYPE, ".utf8");
Util::increase_stack_limit();

Exiv2::XmpParser::initialize();
::atexit(Exiv2::XmpParser::terminate);
Expand Down
Loading