mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 09:00:23 +08:00
extmod/modbinascii: Fix buffer length error.
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>
This commit is contained in:
parent
25fb651566
commit
ae77836370
@ -71,7 +71,7 @@ STATIC mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) {
|
|||||||
byte *in = bufinfo.buf;
|
byte *in = bufinfo.buf;
|
||||||
|
|
||||||
vstr_t vstr;
|
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;
|
byte *out = (byte *)vstr.buf;
|
||||||
|
|
||||||
uint shift = 0;
|
uint shift = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user