Fix JPEG SIMD slicing and padding length handling.

Merged
JI
6mo ago
+11-9

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules :cop:.
  • I have provided test coverage for my change (where applicable)

Description

Fix #3104

This PR fixes a potential access violation in the AVX2 Rgb24 unpack path used by JPEG encoding.

UnpackToRgbPlanesAvx2Reduce processes 8 Rgb24 pixels per iteration (24 bytes), but the AVX2 path begins with a 32-byte vector load. On unpadded rows, the final vectorized iteration could therefore read past the end of the source row even though the logical span length checks passed, which matches the crash reported in #3104.

The fix reduces the AVX2 loop count so we only vectorize chunks that still have the 3-pixel slack required by that 32-byte load. Any remaining pixels are left to the existing scalar tail path.