sprixel_load: guard against bad args #1560

pull/1609/head
nick black 3 years ago committed by Nick Black
parent 2e444a7a23
commit 707d3634eb

@ -147,12 +147,19 @@ sprixel* sprixel_alloc(ncplane* n, int dimy, int dimx){
} }
// |pixy| and |pixx| are the output pixel geometry (i.e. |pixy| must be a // |pixy| and |pixx| are the output pixel geometry (i.e. |pixy| must be a
// multiple of 6 for sixel). takes ownership of 's' on success. // multiple of 6 for sixel). output coverage ought already have been loaded.
// takes ownership of 's' on success. frees any existing glyph.
int sprixel_load(sprixel* spx, char* s, int bytes, int pixy, int pixx, int sprixel_load(sprixel* spx, char* s, int bytes, int pixy, int pixx,
int parse_start){ int parse_start){
assert(spx->n); assert(spx->n);
assert((pixy + s->cellpxy - 1) / s->cellpxy == s->dimy); if(spx->cellpxy > 0){ // don't explode on ncdirect case
assert((pixx + s->cellpxx - 1) / s->cellpxx == s->dimx); if((pixy + spx->cellpxy - 1) / spx->cellpxy != spx->dimy){
return -1;
}
if((pixx + spx->cellpxx - 1) / spx->cellpxx != spx->dimx){
return -1;
}
}
free(spx->glyph); free(spx->glyph);
spx->glyph = s; spx->glyph = s;
spx->glyphlen = bytes; spx->glyphlen = bytes;

Loading…
Cancel
Save