ncblit_*(): sanity check linesize parameter

This commit is contained in:
nick black 2020-11-07 23:13:02 -05:00
parent 2bb546e3ac
commit 07cc29634f
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 6 additions and 2 deletions

View File

@ -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;

View File

@ -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<uint32_t*>(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);
}