fix: IndexOfPattern alignment for multi-byte encodings

Stride the scan by pattern.Length (1 for ASCII/UTF-8, 2 for UTF-16,
4 for UTF-32) to avoid matching a misaligned null-terminator pattern
mid-character.
This commit is contained in:
kbe
2026-07-21 19:34:01 +02:00
parent 6aaee0adce
commit 68255f907c
+2 -1
View File
@@ -273,7 +273,8 @@ public abstract class MemoryBase : IDisposable
private static int IndexOfPattern(byte[] data, byte[] pattern)
{
int lastStart = data.Length - pattern.Length;
for (int i = 0; i <= lastStart; i++)
int stride = Math.Max(1, pattern.Length);
for (int i = 0; i <= lastStart; i += stride)
{
bool match = true;
for (int j = 0; j < pattern.Length; j++)