Skip to content

Commit 1616e62

Browse files
committed
Forward port changes from v0.6 release branch
From release-0.6 branch: Merge a couple of fixes: - module: do not abort when OOM while loading literal (#1689) - Fix potential memory corruption with boxed immediate integers #1690 Also: - CI: release-0.6 bump esp-idf patch versions #1687 - NIFs: fix "warning: initializer-string for character array is too long"
2 parents e616390 + 4f0fe20 commit 1616e62

File tree

6 files changed

+37
-23
lines changed

6 files changed

+37
-23
lines changed

.github/workflows/esp32-build.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@ jobs:
4848
esp-idf-target: ["esp32", "esp32c3", "esp32p4"]
4949
language: ['cpp']
5050
idf-version:
51-
- 'v5.0.7'
52-
- 'v5.1.5'
53-
- 'v5.2.3'
54-
- 'v5.3.2'
55-
- 'v5.4'
51+
- 'v5.0.9'
52+
- 'v5.1.6'
53+
- 'v5.2.5'
54+
- 'v5.3.3'
55+
- 'v5.4.1'
5656

5757
exclude:
5858
- esp-idf-target: "esp32c3"
59-
idf-version: 'v5.0.7'
59+
idf-version: 'v5.0.9'
6060
- esp-idf-target: "esp32c3"
61-
idf-version: 'v5.1.5'
61+
idf-version: 'v5.1.6'
6262
- esp-idf-target: "esp32p4"
63-
idf-version: 'v5.0.7'
63+
idf-version: 'v5.0.9'
6464
- esp-idf-target: "esp32p4"
65-
idf-version: 'v5.1.5'
65+
idf-version: 'v5.1.6'
6666
- esp-idf-target: "esp32p4"
67-
idf-version: 'v5.2.3'
67+
idf-version: 'v5.2.5'
6868

6969
steps:
7070
- name: Checkout repo

.github/workflows/esp32-simtest.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ jobs:
8080
"esp32h2",
8181
"esp32p4",
8282
]
83-
idf-version: ${{ ((contains(github.event.head_commit.message, 'full_sim_test')||contains(github.event.pull_request.title, 'full_sim_test')) && fromJSON('["v5.1.5", "v5.2.3", "v5.3.2", "v5.4"]')) || fromJSON('["v5.3.2"]') }}
83+
idf-version: ${{ ((contains(github.event.head_commit.message, 'full_sim_test')||contains(github.event.pull_request.title, 'full_sim_test')) && fromJSON('["v5.1.6", "v5.2.5", "v5.3.3", "v5.4.1"]')) || fromJSON('["v5.3.3"]') }}
8484
exclude:
8585
- esp-idf-target: "esp32p4"
86-
idf-version: "v5.1.5"
86+
idf-version: "v5.1.6"
8787
- esp-idf-target: "esp32p4"
88-
idf-version: "v5.2.3"
88+
idf-version: "v5.2.5"
8989
- esp-idf-target: "esp32h2"
90-
idf-version: "v5.1.5"
90+
idf-version: "v5.1.6"
9191
- esp-idf-target: "esp32h2"
92-
idf-version: "v5.2.3"
92+
idf-version: "v5.2.5"
9393

9494
steps:
9595
- name: Checkout repo

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ memory error
126126
- Fixed nif_atomvm_posix_read GC bug
127127
- Fixed `erlang:is_number/1` function, now returns true also for floats
128128
- Fixed unlink protocol and add support for `link/1` on ports
129+
- Do not abort when an out of memory happens while loading a literal value
130+
- Fixed potential memory corruption when handling integer immediates that are stored as boxed
131+
integer (this never happens with integers < 28 bits)
129132

130133
### Changed
131134

src/libAtomVM/module.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,8 @@ static struct LiteralEntry *module_build_literals_table(const void *literalsBuf)
446446
term module_load_literal(Module *mod, int index, Context *ctx)
447447
{
448448
term t = externalterm_from_const_literal(mod->literals_table[index].data, mod->literals_table[index].size, ctx);
449-
if (term_is_invalid_term(t)) {
450-
fprintf(stderr, "Invalid term reading literals_table[%i] from module\n", index);
451-
AVM_ABORT();
449+
if (UNLIKELY(term_is_invalid_term(t))) {
450+
fprintf(stderr, "Either OOM or invalid term while reading literals_table[%i] from module\n", index);
452451
}
453452
return t;
454453
}

src/libAtomVM/nifs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4613,7 +4613,13 @@ static term nif_console_print(Context *ctx, int argc, term argv[])
46134613
return OK_ATOM;
46144614
}
46154615

4616-
static char b64_table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4616+
static char b64_table[64] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
4617+
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
4618+
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
4619+
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
4620+
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
4621+
'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
4622+
'8', '9', '+', '/'};
46174623

46184624
// per https://tools.ietf.org/rfc/rfc4648.txt
46194625

src/libAtomVM/opcodesswitch.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,21 +1568,27 @@ static term maybe_alloc_boxed_integer_fragment(Context *ctx, avm_int64_t value)
15681568
{
15691569
#if BOXED_TERMS_REQUIRED_FOR_INT64 > 1
15701570
if ((value < AVM_INT_MIN) || (value > AVM_INT_MAX)) {
1571-
if (UNLIKELY(memory_ensure_free_opt(ctx, BOXED_INT64_SIZE, MEMORY_NO_GC) != MEMORY_GC_OK)) {
1571+
Heap heap;
1572+
if (UNLIKELY(memory_init_heap(&heap, BOXED_INT64_SIZE) != MEMORY_GC_OK)) {
15721573
ctx->x[0] = ERROR_ATOM;
15731574
ctx->x[1] = OUT_OF_MEMORY_ATOM;
15741575
return term_invalid_term();
15751576
}
1576-
return term_make_boxed_int64(value, &ctx->heap);
1577+
memory_heap_append_heap(&ctx->heap, &heap);
1578+
1579+
return term_make_boxed_int64(value, &heap);
15771580
} else
15781581
#endif
15791582
if ((value < MIN_NOT_BOXED_INT) || (value > MAX_NOT_BOXED_INT)) {
1580-
if (UNLIKELY(memory_ensure_free_opt(ctx, BOXED_INT_SIZE, MEMORY_NO_GC) != MEMORY_GC_OK)) {
1583+
Heap heap;
1584+
if (UNLIKELY(memory_init_heap(&heap, BOXED_INT_SIZE) != MEMORY_GC_OK)) {
15811585
ctx->x[0] = ERROR_ATOM;
15821586
ctx->x[1] = OUT_OF_MEMORY_ATOM;
15831587
return term_invalid_term();
15841588
}
1585-
return term_make_boxed_int(value, &ctx->heap);
1589+
memory_heap_append_heap(&ctx->heap, &heap);
1590+
1591+
return term_make_boxed_int(value, &heap);
15861592
} else {
15871593
return term_from_int(value);
15881594
}

0 commit comments

Comments
 (0)