Skip to content

Commit

Permalink
Fix possible off by 1 error when reading strings
Browse files Browse the repository at this point in the history
  • Loading branch information
luizzeroxis committed Aug 23, 2024
1 parent 6f470f8 commit 5298e42
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion UndertaleModLib/Util/BufferBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModLib/Util/FileBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5298e42

Please sign in to comment.