Skip to content

Commit 40cec12

Browse files
committed
Fix LZ4 Decode
1 parent 7d6e07c commit 40cec12

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

  • UnityAsset.NET/Compression

UnityAsset.NET/Compression/LZ4.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static unsafe int Decode(ReadOnlySpan<byte> source, Span<byte> target)
2727
literalLength += b;
2828
} while (b == 0xFF && s < sourceEnd);
2929
}
30+
3031
Buffer.MemoryCopy(s, t, literalLength, literalLength);
3132
s += literalLength;
3233
t += literalLength;
@@ -43,10 +44,24 @@ public static unsafe int Decode(ReadOnlySpan<byte> source, Span<byte> target)
4344
matchLength += b;
4445
} while (b == 0xFF && s < sourceEnd);
4546
}
47+
4648
matchLength += 4;
47-
Buffer.MemoryCopy(t - offset, t, matchLength, matchLength);
49+
50+
while (matchLength > offset)
51+
{
52+
Buffer.MemoryCopy(t - offset, t, offset, offset);
53+
t += offset;
54+
matchLength -= offset;
55+
}
56+
57+
if (matchLength > 0)
58+
{
59+
Buffer.MemoryCopy(t - offset, t, matchLength, matchLength);
60+
}
61+
4862
t += matchLength;
4963
}
64+
5065
return (int)(t - targetPtr);
5166
}
5267
}

0 commit comments

Comments
 (0)