Skip to content

Commit

Permalink
Fixed ByteArrayBuilder.TrimNewLine() to check array bounds properly
Browse files Browse the repository at this point in the history
Fixes issue #1634
  • Loading branch information
jstedfast committed Aug 31, 2023
1 parent e84d570 commit 70d6482
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions MailKit/ByteArrayBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public bool Equals (string value, bool ignoreCase = false)
public void TrimNewLine ()
{
// Trim the <CR><LF> sequence from the end of the line.
if (buffer[length - 1] == (byte) '\n') {
if (length > 0 && buffer[length - 1] == (byte) '\n') {
length--;

if (buffer[length - 1] == (byte) '\r')
if (length > 0 && buffer[length - 1] == (byte) '\r')
length--;
}
}
Expand Down

0 comments on commit 70d6482

Please sign in to comment.