Skip to content

Commit

Permalink
Actually Fixed: Out of Bounds Potential Read on Pattern Not Found in …
Browse files Browse the repository at this point in the history
…Vectorised Impl
  • Loading branch information
Sewer56 committed Aug 23, 2023
1 parent 8a41729 commit 9760d49
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion External/Reloaded.Memory.SigScan.ReloadedII/ModConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"ModId": "Reloaded.Memory.SigScan.ReloadedII",
"ModName": "Library: Reloaded.Memory.Sigscan for Reloaded II",
"ModAuthor": "Sewer56",
"ModVersion": "1.2.11",
"ModVersion": "1.2.13",
"ModDescription": "Shared implementation of Reloaded.Memory.Sigscan",
"ModDll": "Reloaded.Memory.SigScan.ReloadedII.dll",
"ModIcon": "Preview.png",
Expand Down
2 changes: 1 addition & 1 deletion Reloaded.Memory.Sigscan/Reloaded.Memory.Sigscan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<LangVersion>preview</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Version>3.1.6</Version>
<Version>3.1.8</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0' And '$(TargetFramework)' != 'netstandard2.1'">
Expand Down
7 changes: 6 additions & 1 deletion Reloaded.Memory.Sigscan/Scanner_AVX2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static PatternScanResult FindPatternAvx2(byte* data, int dataLength, stri
int matchTableLength = matchTable.Length;

var firstByteVec = Vector256.Create(patternData.Bytes[patternData.LeadingIgnoreCount]);
int searchLength = dataLength - Math.Max(patternData.Bytes.Length >> 5 << 5, AvxRegisterLength); // bitshift rounds down
int searchLength = dataLength - (patternData.Bytes.Length + AvxRegisterLength);

int leadingIgnoreCount = patternData.LeadingIgnoreCount;
ref var pVec = ref patternVectors[0];
Expand All @@ -68,6 +68,11 @@ public static PatternScanResult FindPatternAvx2(byte* data, int dataLength, stri
var dataMaxPtr = dataPtr + searchLength;
for (; dataPtr < dataMaxPtr; dataPtr++)
{
if (dataPtr > (void*)0x00000001778b1000)
{
var a = 5;

Check warning on line 73 in Reloaded.Memory.Sigscan/Scanner_AVX2.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'a' is assigned but its value is never used

Check warning on line 73 in Reloaded.Memory.Sigscan/Scanner_AVX2.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'a' is assigned but its value is never used

Check warning on line 73 in Reloaded.Memory.Sigscan/Scanner_AVX2.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'a' is assigned but its value is never used

Check warning on line 73 in Reloaded.Memory.Sigscan/Scanner_AVX2.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'a' is assigned but its value is never used

Check warning on line 73 in Reloaded.Memory.Sigscan/Scanner_AVX2.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'a' is assigned but its value is never used

Check warning on line 73 in Reloaded.Memory.Sigscan/Scanner_AVX2.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'a' is assigned but its value is never used
}

// Problem: If pattern starts with unknown, will never match.
var rhs = Avx.LoadVector256(dataPtr);
var equal = Avx2.CompareEqual(pFirstByteVec, rhs);
Expand Down
2 changes: 1 addition & 1 deletion Reloaded.Memory.Sigscan/Scanner_SSE2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static PatternScanResult FindPatternSse2(byte* data, int dataLength, stri
int matchTableLength = matchTable.Length;

var firstByteVec = Vector128.Create(patternData.Bytes[patternData.LeadingIgnoreCount]);
int searchLength = dataLength - Math.Max(patternData.Bytes.Length >> 4 << 4, SseRegisterLength); // bitshift rounds down
int searchLength = dataLength - (patternData.Bytes.Length + SseRegisterLength);

int leadingIgnoreCount = patternData.LeadingIgnoreCount;
ref var pVec = ref patternVectors[0];
Expand Down

0 comments on commit 9760d49

Please sign in to comment.