Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ class LoopSearch
//
BasicBlock* FindEntry(BasicBlock* head, BasicBlock* top, BasicBlock* bottom)
{
if (head->bbJumpKind == BBJ_ALWAYS)
if ((head->bbJumpKind == BBJ_ALWAYS) && !head->isBBCallAlwaysPairTail())
{
if (head->bbJumpDest->bbNum <= bottom->bbNum && head->bbJumpDest->bbNum >= top->bbNum)
{
Expand Down
74 changes: 74 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_108811/Runtime_108811.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.IO;
using System.Text;
using System.Threading;
using Xunit;

public class Runtime_108811
{
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
[Fact]
public static int Test()
{
var hex = "3AE46205A50ED00E7612A91692552B7A";
var key = "abcdef1234567890";
var iv = "abcdef1234567890";
var bytes = Convert.FromHexString(hex);
int retval = 100;
for (int i = 0; i < 200; i++)
{
var result = new Runtime_108811().Decrypt(bytes, key, iv, out _);
Console.Write($"{result} ");
if (result != 9)
{
retval = -1;
break;
}
Thread.Sleep(10);
}
Console.WriteLine();
return retval;
}

public int Decrypt(byte[] buffer, string key, string iv, out byte[] decryptedData)
{
int decryptedByteCount = 0;
decryptedData = new byte[buffer.Length];

using var aes = Aes.Create();
aes.Mode = CipherMode.CBC;
aes.KeySize = 128;
aes.Padding = PaddingMode.Zeros;

var instPwdArray = Encoding.ASCII.GetBytes(key);
var instSaltArray = Encoding.ASCII.GetBytes(iv);

using (var decryptor = aes.CreateDecryptor(instPwdArray, instSaltArray))
{
using (var memoryStream = new MemoryStream(buffer))
{
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
{
int read;
do
{
read = cryptoStream.Read(
decryptedData,
decryptedByteCount,
decryptedData.Length - decryptedByteCount);
decryptedByteCount += read;
} while (read != 0);
}
}
}
// Found the accurate length of decrypted data
while (decryptedData[decryptedByteCount - 1] == 0 && decryptedByteCount > 0)
Copy link

Copilot AI Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The while-loop condition checks the array element before confirming that decryptedByteCount is greater than 0, which could lead to an out-of-range access. Consider swapping the operands to 'while (decryptedByteCount > 0 && decryptedData[decryptedByteCount - 1] == 0)'.

Suggested change
while (decryptedData[decryptedByteCount - 1] == 0 && decryptedByteCount > 0)
while (decryptedByteCount > 0 && decryptedData[decryptedByteCount - 1] == 0)

Copilot uses AI. Check for mistakes.
decryptedByteCount--;
return decryptedByteCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,9 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_90219/Runtime_90219/*">
<Issue>Loads an assembly from file</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_108811/Runtime_108811/*">
<Issue>Requires AES</Issue>
</ExcludeList>
</ItemGroup>

<ItemGroup Condition="'$(TargetArchitecture)' == 'wasm'">
Expand Down
Loading