Skip to content

Commit

Permalink
ncvisual_from_*(): check geometries for validity
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Jun 11, 2024
1 parent 21429da commit 87ff6fb
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/lib/visual.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,10 @@ ncvisual* ncvisual_from_rgba(const void* rgba, int rows, int rowstride, int cols
logerror("rowstride %d not a multiple of 4", rowstride);
return NULL;
}
if(rowstride * 4 < cols || cols <= 0 || rows <= 0){
logerror("invalid rowstride or geometry");
return NULL;
}
ncvisual* ncv = ncvisual_create();
if(ncv){
// ffmpeg needs inputs with rows aligned on 192-byte boundaries
Expand Down Expand Up @@ -812,6 +816,14 @@ ncvisual* ncvisual_from_sixel(const char* s, unsigned leny, unsigned lenx){

ncvisual* ncvisual_from_rgb_packed(const void* rgba, int rows, int rowstride,
int cols, int alpha){
if(rowstride % 3){
logerror("rowstride %d not a multiple of 3", rowstride);
return NULL;
}
if(rows <= 0 || cols <= 0 || rowstride < cols * 3){
logerror("illegal packed rgb geometry");
return NULL;
}
ncvisual* ncv = ncvisual_create();
if(ncv){
ncv->rowstride = pad_for_image(cols * 4, cols);
Expand Down Expand Up @@ -849,6 +861,10 @@ ncvisual* ncvisual_from_rgb_loose(const void* rgba, int rows, int rowstride,
logerror("rowstride %d not a multiple of 4", rowstride);
return NULL;
}
if(rows <= 0 || cols <= 0 || rowstride < cols * 4){
logerror("illegal packed rgb geometry");
return NULL;
}
ncvisual* ncv = ncvisual_create();
if(ncv){
ncv->rowstride = pad_for_image(cols * 4, cols);
Expand All @@ -874,6 +890,11 @@ ncvisual* ncvisual_from_rgb_loose(const void* rgba, int rows, int rowstride,

ncvisual* ncvisual_from_bgra(const void* bgra, int rows, int rowstride, int cols){
if(rowstride % 4){
logerror("rowstride %d not a multiple of 4", rowstride);
return NULL;
}
if(rows <= 0 || cols <= 0 || rowstride < cols * 4){
logerror("illegal bgra geometry");
return NULL;
}
ncvisual* ncv = ncvisual_create();
Expand Down Expand Up @@ -907,10 +928,14 @@ ncvisual* ncvisual_from_bgra(const void* bgra, int rows, int rowstride, int cols
ncvisual* ncvisual_from_palidx(const void* pdata, int rows, int rowstride,
int cols, int palsize, int pstride,
const uint32_t* palette){
if(rowstride % pstride){
if(pstride <= 0 || rowstride % pstride){
logerror("bad pstride (%d) for rowstride (%d)", pstride, rowstride);
return NULL;
}
if(rows <= 0 || cols <= 0 || rowstride < cols * pstride){
logerror("illegal palimg geometry");
return NULL;
}
if(palsize > 256 || palsize <= 0){
logerror("palettes size (%d) is unsupported", palsize);
return NULL;
Expand Down

0 comments on commit 87ff6fb

Please sign in to comment.