Skip to content

Commit f5377cb

Browse files
committed
Fix memory allocation bug in base64_encode
This bug currently cannot yield a crash because the miscalculation is preceded by an allocation which includes the MIN_FREE_SPACE_SIZE margin, larger than padding. Signed-off-by: Paul Guyot <[email protected]>
1 parent 1950aaa commit f5377cb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libAtomVM/nifs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3229,7 +3229,7 @@ static term base64_encode(Context *ctx, int argc, term argv[], bool return_binar
32293229
size_t dst_size_with_pad = dst_size + pad;
32303230
size_t heap_free = return_binary ?
32313231
term_binary_data_size_in_terms(dst_size_with_pad) + BINARY_HEADER_SIZE
3232-
: 2*dst_size;
3232+
: 2*dst_size_with_pad;
32333233
if (UNLIKELY(memory_ensure_free(ctx, heap_free) != MEMORY_GC_OK)) {
32343234
RAISE_ERROR(OUT_OF_MEMORY_ATOM);
32353235
}

0 commit comments

Comments
 (0)