From 5298e426eb6dec3c21e7b3fde3148814dab76d6e Mon Sep 17 00:00:00 2001 From: luizzeroxis Date: Fri, 23 Aug 2024 20:38:41 -0300 Subject: [PATCH] Fix possible off by 1 error when reading strings --- UndertaleModLib/Util/BufferBinaryReader.cs | 2 +- UndertaleModLib/Util/FileBinaryReader.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/UndertaleModLib/Util/BufferBinaryReader.cs b/UndertaleModLib/Util/BufferBinaryReader.cs index 17a12f3d9..1e09ae99e 100644 --- a/UndertaleModLib/Util/BufferBinaryReader.cs +++ b/UndertaleModLib/Util/BufferBinaryReader.cs @@ -286,7 +286,7 @@ public string ReadGMString() if (length < 0) throw new IOException("Invalid string length"); - if (chunkBuffer.Position + length + 1 >= _length) + if (chunkBuffer.Position + length + 1 > _length) // "+ 1" because of the null terminator throw new IOException("Reading out of chunk bounds"); string res; diff --git a/UndertaleModLib/Util/FileBinaryReader.cs b/UndertaleModLib/Util/FileBinaryReader.cs index 98db5e992..2527fbd01 100644 --- a/UndertaleModLib/Util/FileBinaryReader.cs +++ b/UndertaleModLib/Util/FileBinaryReader.cs @@ -214,7 +214,7 @@ public string ReadGMString() if (length < 0) throw new IOException("Invalid string length"); - if (Stream.Position + length + 1 >= _length) + if (Stream.Position + length + 1 > _length) // "+ 1" because of the null terminator throw new IOException("Reading out of bounds"); string res;