diff --git a/src/BmpFile.cc b/src/BmpFile.cc index ae0e93b..010573e 100644 --- a/src/BmpFile.cc +++ b/src/BmpFile.cc @@ -765,6 +765,16 @@ void BmpFile::readdata () paddinglength = 4 - (linelength % 4) ; } + unsigned long long total_bytes_needed = (unsigned long long)height * (unsigned long long)linelength; + + const unsigned long long MAX_ALLOWED_BYTES = 500ULL * 1024ULL * 1024ULL; + + if (total_bytes_needed > MAX_ALLOWED_BYTES) { + fprintf(stderr, "[!] SECURITY ERROR: BMP file requires %llu bytes, which exceeds the limit of %llu bytes.\n", total_bytes_needed, MAX_ALLOWED_BYTES); + fprintf(stderr, "[!] Execution aborted to prevent Memory Exhaustion/DoS.\n"); + exit(1); + } + BitmapData.resize (height * linelength) ; for (unsigned long line = 0 ; line < height ; line++) { for (unsigned long posinline = 0 ; posinline < linelength ; posinline++) { diff --git a/src/Embedder.cc b/src/Embedder.cc index 25f748e..75d5d2a 100644 --- a/src/Embedder.cc +++ b/src/Embedder.cc @@ -157,7 +157,7 @@ void Embedder::embed () cvrstring = "\"" + Args.CvrFn.getValue() + "\"" ; } char buf[200] ; - sprintf (buf, _("embedding %s in %s..."), embstring.c_str(), cvrstring.c_str()) ; + snprintf(buf, sizeof(buf), _("embedding %s in %s..."), embstring.c_str(), cvrstring.c_str()); prout = new ProgressOutput (std::string(buf)) ; }