diff --git a/src/lib/blit.c b/src/lib/blit.c index ffb9ab338..25f77c705 100644 --- a/src/lib/blit.c +++ b/src/lib/blit.c @@ -833,6 +833,9 @@ int ncblit_bgrx(const void* data, int linesize, const struct ncvisual_options* v if(vopts->flags > NCVISUAL_OPTION_BLEND){ return -1; } + if(linesize <= 0 || (size_t)linesize < vopts->lenx * sizeof(uint32_t)){ + return -1; + } struct ncplane* nc = vopts->n; if(nc == NULL){ return -1; @@ -872,6 +875,9 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v if(vopts->flags > NCVISUAL_OPTION_BLEND){ return -1; } + if(linesize <= 0 || (size_t)linesize < vopts->lenx * sizeof(uint32_t)){ + return -1; + } struct ncplane* nc = vopts->n; if(nc == NULL){ return -1; diff --git a/src/lib/visual.cpp b/src/lib/visual.cpp index 13929888a..d8aac8817 100644 --- a/src/lib/visual.cpp +++ b/src/lib/visual.cpp @@ -59,14 +59,12 @@ auto bgra_to_rgba(const void* data, int rows, int rowstride, int cols) -> void* if(rowstride % 4){ // must be a multiple of 4 bytes return nullptr; } -//fprintf(stderr, "ROWS: %d\n", rows); auto ret = static_cast(malloc(rowstride * rows)); if(ret){ for(int y = 0 ; y < rows ; ++y){ for(int x = 0 ; x < cols ; ++x){ const uint32_t* src = (const uint32_t*)data + (rowstride / 4) * y + x; uint32_t* dst = ret + (rowstride / 4) * y + x; -//fprintf(stderr, "SRC: %x DST: %x\n", *src, *dst); *dst = ((*src & 0xff00u) << 16u) | (*src & 0xff00ffu) | ((*src & 0xff000000) >> 16u); //fprintf(stderr, "y: %d x: %d SRC: %x DST: %x\n", y, x, *src, *dst); }