From ae778363702a759e987bb9209165f5a413dbd8a9 Mon Sep 17 00:00:00 2001 From: Duncan Lowther Date: Wed, 14 Jun 2023 15:03:14 +0100 Subject: [PATCH] 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 ( / 4) * 3 + 1, which may be less due to integer division. Changed to ( * 3) / 4 + 1. Signed-off-by: Duncan Lowther --- extmod/modbinascii.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extmod/modbinascii.c b/extmod/modbinascii.c index 46027d5fd5c1..183cd3fc1789 100644 --- a/extmod/modbinascii.c +++ b/extmod/modbinascii.c @@ -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;