From 11072bc0dbe4f41ea87839dfed369ddfe7c3864a Mon Sep 17 00:00:00 2001 From: Jordan Peck Date: Sat, 5 Nov 2022 21:39:58 +0000 Subject: [PATCH] Fix crash in NewFromEncodedNodeTree when passing in zero length string --- CMakeLists.txt | 2 +- src/FastNoise/Base64.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f107329d..f2d43ad8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # CMakeList.txt : CMake project for FastNoise2 cmake_minimum_required(VERSION 3.7.1) -project(FastNoise2 VERSION 0.9.6) +project(FastNoise2 VERSION 0.9.7) set(CMAKE_CXX_STANDARD 17) message("FastNoise2 Arch: ${CMAKE_SYSTEM_PROCESSOR}") diff --git a/src/FastNoise/Base64.h b/src/FastNoise/Base64.h index 0eef545e..9d7449fa 100644 --- a/src/FastNoise/Base64.h +++ b/src/FastNoise/Base64.h @@ -99,9 +99,10 @@ namespace FastNoise }; size_t in_len = std::strlen( input ); - if( in_len % 4 != 0 ) return {}; - size_t out_len = in_len / 4 * 3; + + if( out_len == 0 || in_len % 4 != 0 ) return {}; + if( input[in_len - 1] == '=' ) out_len--; if( input[in_len - 2] == '=' ) out_len--;