From 86f2c64263b1c348188bba7760f1b6ca9ef43b6c Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 16 May 2023 18:53:32 +0200 Subject: [PATCH] tinshift: raise maximum size of JSON file to 100 MB (fixes #3732) Loading a 60 MB JSON file takes ~ 3 seconds on a release build, and consumes ~ 1.3 GB RAM according to Valgrind --- src/transformations/tinshift.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/transformations/tinshift.cpp b/src/transformations/tinshift.cpp index c780e5d4bd..bd3cce09a0 100644 --- a/src/transformations/tinshift.cpp +++ b/src/transformations/tinshift.cpp @@ -94,15 +94,20 @@ PJ *TRANSFORMATION(tinshift, 1) { file->seek(0, SEEK_END); unsigned long long size = file->tell(); // Arbitrary threshold to avoid ingesting an arbitrarily large JSON file, - // that could be a denial of service risk. 10 MB should be sufficiently + // that could be a denial of service risk. 100 MB should be sufficiently // large for any valid use ! - if (size > 10 * 1024 * 1024) { + if (size > 100 * 1024 * 1024) { proj_log_error(P, _("File %s too large"), filename); return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } file->seek(0); std::string jsonStr; - jsonStr.resize(static_cast(size)); + try { + jsonStr.resize(static_cast(size)); + } catch (const std::bad_alloc &) { + proj_log_error(P, _("Cannot read %s. Not enough memory"), filename); + return destructor(P, PROJ_ERR_OTHER); + } if (file->read(&jsonStr[0], jsonStr.size()) != jsonStr.size()) { proj_log_error(P, _("Cannot read %s"), filename); return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);