Skip to content

Commit 36ec5c0

Browse files
authored
Fixed integer overflow in AuthenticatedEncryptionProvider.cs (#3063)
An overflow in the arithmetic expression authenticatedData.Length * 8 with type int(32 bits, signed) can occur before casting into wider type long(64 bits, signed)
1 parent ead4201 commit 36ec5c0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Microsoft.IdentityModel.Tokens/Encryption/AuthenticatedEncryptionProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private AuthenticatedEncryptionResult EncryptWithAesCbc(byte[] plaintext, byte[]
152152
throw LogHelper.LogExceptionMessage(new SecurityTokenEncryptionFailedException(LogHelper.FormatInvariant(LogMessages.IDX10654, ex)));
153153
}
154154

155-
byte[] al = Utility.ConvertToBigEndian(authenticatedData.Length * 8);
155+
byte[] al = Utility.ConvertToBigEndian(authenticatedData.Length * 8L);
156156
byte[] macBytes = new byte[authenticatedData.Length + aes.IV.Length + ciphertext.Length + al.Length];
157157
Array.Copy(authenticatedData, 0, macBytes, 0, authenticatedData.Length);
158158
Array.Copy(aes.IV, 0, macBytes, authenticatedData.Length, aes.IV.Length);
@@ -173,7 +173,7 @@ private byte[] DecryptWithAesCbc(byte[] ciphertext, byte[] authenticatedData, by
173173
throw LogHelper.LogExceptionMessage(new SecurityTokenDecryptionFailedException(
174174
LogHelper.FormatInvariant(LogMessages.IDX10625, authenticationTag.Length, expectedTagLength, Base64UrlEncoder.Encode(authenticationTag), Algorithm)));
175175

176-
byte[] al = Utility.ConvertToBigEndian(authenticatedData.Length * 8);
176+
byte[] al = Utility.ConvertToBigEndian(authenticatedData.Length * 8L);
177177
byte[] macBytes = new byte[authenticatedData.Length + iv.Length + ciphertext.Length + al.Length];
178178
Array.Copy(authenticatedData, 0, macBytes, 0, authenticatedData.Length);
179179
Array.Copy(iv, 0, macBytes, authenticatedData.Length, iv.Length);

0 commit comments

Comments
 (0)