From 640db1ed3fa0f15763439ae331d78d88cd932ee5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 25 Apr 2020 17:38:16 +0200 Subject: zimg: don't assume zimg reads are 64 byte aligned Only _writes_ are aligned, so the assumption doesn't work for reads. But it's easy to fix by rounding down x0 to the next byte boundary. Writing pixels outside of the read area is allowed, and we don't go out of buffer bounds. Patch by anon32, permission to do anything with it. --- video/zimg.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/video/zimg.c b/video/zimg.c index 2f52537c07..b478ccbd1d 100644 --- a/video/zimg.c +++ b/video/zimg.c @@ -561,10 +561,6 @@ static int bitmap_repack(void *user, unsigned i, unsigned x0, unsigned x1) { struct mp_zimg_repack *r = user; - // Supposedly zimg aligns this at least on 64 byte boundaries. Simplifies a - // lot for us. - assert(!(x0 & 7)); - uint8_t *p1 = r->mpi->planes[0] + r->mpi->stride[0] * (ptrdiff_t)(i - r->mpi_y0); uint8_t *p2 = @@ -572,6 +568,10 @@ static int bitmap_repack(void *user, unsigned i, unsigned x0, unsigned x1) uint8_t swap = r->comp_size ? 0xFF : 0; if (r->pack) { + // Supposedly zimg aligns this at least on 64 byte boundaries. Simplifies a + // lot for us. + assert(!(x0 & 7)); + for (int x = x0; x < x1; x += 8) { uint8_t d = 0; int max_b = MPMIN(8, x1 - x); @@ -580,6 +580,8 @@ static int bitmap_repack(void *user, unsigned i, unsigned x0, unsigned x1) p1[x / 8] = d ^ swap; } } else { + x0 &= ~0x7; + for (int x = x0; x < x1; x += 8) { uint8_t d = p1[x / 8] ^ swap; int max_b = MPMIN(8, x1 - x); -- cgit v1.2.3