Skip to content

Commit

Permalink
extmod/modframebuf: Fix invalid stride for odd widths in GS4_HMSB fmt.
Browse files Browse the repository at this point in the history
Since the stride is specified in pixels, in a 4-bit horizontal format it
has to always be even, otherwise the computation is wrong and we can
write outside of the buffer sometimes.
  • Loading branch information
deshipu authored and dpgeorge committed Jul 25, 2017
1 parent a10467b commit 363087a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion extmod/modframebuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,14 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
switch (o->format) {
case FRAMEBUF_MVLSB:
case FRAMEBUF_RGB565:
case FRAMEBUF_GS4_HMSB:
break;
case FRAMEBUF_MHLSB:
case FRAMEBUF_MHMSB:
o->stride = (o->stride + 7) & ~7;
break;
case FRAMEBUF_GS4_HMSB:
o->stride = (o->stride + 1) & ~1;
break;
default:
mp_raise_ValueError("invalid format");
}
Expand Down

0 comments on commit 363087a

Please sign in to comment.