diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs index 7d4f7ee842..c33a8a1968 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -123,6 +123,7 @@ internal class ComponentProcessor : IDisposable ref Vector256 sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed + DebugGuard.IsTrue(source.Length % 8 == 0, "source must be multiple of 8"); nuint count = source.Vector256Count(); for (nuint i = 0; i < count; i++) { @@ -135,6 +136,7 @@ internal class ComponentProcessor : IDisposable ref Vector128 sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed + DebugGuard.IsTrue(source.Length % 8 == 0, "source must be multiple of 8"); nuint count = source.Vector128Count(); for (nuint i = 0; i < count; i++) { @@ -213,6 +215,7 @@ internal class ComponentProcessor : IDisposable ref Vector256 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed + DebugGuard.IsTrue(target.Length % 8 == 0, "target must be multiple of 8"); nuint count = target.Vector256Count(); Vector256 multiplierVector = Vector256.Create(multiplier); for (nuint i = 0; i < count; i++) @@ -225,6 +228,7 @@ internal class ComponentProcessor : IDisposable ref Vector128 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target)); // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed + DebugGuard.IsTrue(target.Length % 8 == 0, "target must be multiple of 8"); nuint count = target.Vector128Count(); Vector128 multiplierVector = Vector128.Create(multiplier); for (nuint i = 0; i < count; i++)