From 8db68215c5f79206799441dd2f82911853e8f686 Mon Sep 17 00:00:00 2001 From: Ivan Belokobylskiy Date: Wed, 24 Apr 2019 13:08:03 +0300 Subject: [PATCH] Limit blit_buffer to w * h size, no overflow --- VERSION | 2 +- st7789/st7789.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 17e51c3..d917d3e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.1 +0.1.2 diff --git a/st7789/st7789.c b/st7789/st7789.c index 860d6a5..4daf912 100644 --- a/st7789/st7789.c +++ b/st7789/st7789.c @@ -22,7 +22,7 @@ * THE SOFTWARE. */ -#define __ST7789_VERSION__ "0.1.1" +#define __ST7789_VERSION__ "0.1.2" #include "py/obj.h" #include "py/runtime.h" @@ -355,9 +355,10 @@ STATIC mp_obj_t st7789_ST7789_blit_buffer(size_t n_args, const mp_obj_t *args) { CS_LOW(); const int buf_size = 256; + int limit = MIN(buf_info.len, w * h * 2); + int chunks = limit / buf_size; + int rest = limit % buf_size; int i = 0; - int chunks = buf_info.len / buf_size; - int rest = buf_info.len % buf_size; for (; i < chunks; i ++) { write_spi(self->spi_obj, (const uint8_t*)buf_info.buf + i*buf_size, buf_size); }