summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-04-25 17:38:16 +0200
committerwm4 <wm4@nowhere>2020-04-25 17:38:54 +0200
commit640db1ed3fa0f15763439ae331d78d88cd932ee5 (patch)
treef461bfcb44f9d4ab241f150ecfe7bf5c2b124bd2
parent4deae5e4b53220c5becd7312a4b0d7f5707d5757 (diff)
downloadmpv-640db1ed3fa0f15763439ae331d78d88cd932ee5.tar.bz2
mpv-640db1ed3fa0f15763439ae331d78d88cd932ee5.tar.xz
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.
-rw-r--r--video/zimg.c10
1 files 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);