Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix heap overflow with invalid string length in binary resources

Rémi Verscheldec67e2529f63e
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index c41bc281c3b..6d909d68b33 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -851,6 +851,10 @@ static void save_ustring(Ref<FileAccess> r_file, const String &p_string) {
static String get_ustring(Ref<FileAccess> r_file) {
int len = r_file->get_32();
+ ERR_FAIL_COND_V_MSG(len < 0 || (uint64_t)len > r_file->get_length() - r_file->get_position(), String(), "Invalid string length, corrupt binary resource.");
+ if (len == 0) {
+ return String();
+ }
Vector<char> str_buf;
str_buf.resize(len);
r_file->get_buffer((uint8_t *)&str_buf[0], len);
@@ -859,6 +863,7 @@ static String get_ustring(Ref<FileAccess> r_file) {
String ResourceLoaderBinary::get_unicode_string() {
int len = f->get_32();
+ ERR_FAIL_COND_V_MSG(len < 0 || (uint64_t)len > f->get_length() - f->get_position(), String(), "Invalid string length, corrupt binary resource.");
if (len > str_buf.size()) {
str_buf.resize(len);
}