Skip to content

Commit

Permalink
extmod/modbinascii: Fix buffer length error.
Browse files Browse the repository at this point in the history
The mod_binascii_a2b_base64() function allocates a buffer which may be
too small. It needs to be no less than three-quarters of the input
length, but is calculated as (<length> / 4) * 3 + 1, which may be less
due to integer division. Changed to (<length> * 3) / 4 + 1.

Signed-off-by: Duncan Lowther <Duncan.Lowther@glasgow.ac.uk>
  • Loading branch information
djlowther committed Jun 21, 2023
1 parent 25fb651 commit ae77836
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion extmod/modbinascii.c
Expand Up @@ -71,7 +71,7 @@ STATIC mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) {
byte *in = bufinfo.buf;

vstr_t vstr;
vstr_init(&vstr, (bufinfo.len / 4) * 3 + 1); // Potentially over-allocate
vstr_init(&vstr, (bufinfo.len * 3) / 4 + 1); // Potentially over-allocate
byte *out = (byte *)vstr.buf;

uint shift = 0;
Expand Down

0 comments on commit ae77836

Please sign in to comment.