Skip to content

Commit 1b6d89e

Browse files
committed
bricks/_common/micropython.c: Handle unaligned module size
Because the storage layer rounds up code size to a multiple of the word size, it is possible for the set of code modules to have trailing padding. Previously, this could cause the module search function to not terminate as expected, read out of bounds, and crash.
1 parent 1d0471d commit 1b6d89e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bricks/_common/micropython.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static uint8_t *mpy_data_get_buf(mpy_info_t *info) {
240240
static mpy_info_t *mpy_data_find(qstr name) {
241241
const char *name_str = qstr_str(name);
242242

243-
for (mpy_info_t *info = mpy_first; info < mpy_end;
243+
for (mpy_info_t *info = mpy_first; (uintptr_t)info + sizeof(uint32_t) < (uintptr_t)mpy_end;
244244
info = (mpy_info_t *)(mpy_data_get_buf(info) + pbio_get_uint32_le(info->mpy_size))) {
245245
if (strcmp(info->mpy_name, name_str) == 0) {
246246
return info;

0 commit comments

Comments
 (0)