Commit Graph
3 Commits
Author SHA1 Message Date
Isaac ConnorandClaude Opus 5.5 fe747e3892 fix: blend whole helper blocks on the YUV luma path of Image::Blend refs #5601
The in-place luma blend for planar YUV added in 0574a4eb3 calls the blend
helper with linesize * height, bypassing the block split in Blend. The
NEON helper consumes 64 bytes per iteration, so a Y plane that is not a
multiple of 64 (a 32-byte linesize and an odd height) ran its loop off the
end of memory. On macOS arm64 the Image::Blend odd-size test died with
SIGBUS whenever an earlier test had selected the SIMD helpers.

Move the block split into BlendBlocks() and use it for both paths. Add a
YUV420P case whose luma plane is 160 bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 11:45:06 -05:00
Isaac ConnorandClaude Opus 5.5 81ab657a19 fix: copy the blend result into a buffer Image::Blend does not own
Unless the buffer was held, Blend swapped the image's buffer with its
blend buffer. The blend buffer is freed with zm_freealigned(), so swapping
in a caller's buffer, or one from malloc or new, freed memory the image
did not own or freed it the wrong way: a double free for an image over a
caller's buffer. The swap also left allocation describing the old buffer.

Swap only a buffer from AllocBuffer() and swap the allocation sizes with
it; copy the result back otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 16:15:24 -05:00
Isaac ConnorandClaude Opus 5.5 187115c68e fix: blend whole helper blocks in Image::Blend
Blend handed the image's whole buffer to the fast blend helper, which
consumes 16 bytes per iteration (unrolled C, SSE2) or 64 (NEON). The SIMD
variants wrap their loop counter past zero on a count that is not a
multiple of their block and run off the end of memory; the C one overruns
by up to a block. size is only a multiple of 32 for an aligned image, so an
odd number of rows at a width such as 1366 crashed NEON, and an image over a
caller's unaligned buffer could crash SSE2 too.

Blend the 64-byte bulk in place and the remainder through zero-padded
64-byte copies, so every byte still goes through the selected helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 16:15:23 -05:00