Byte-aligned bignum segment is written over the rest of the binary
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 56/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c, erlang
- Domain
- backend, embedded-iot
Research direction
Start in opcodesswitch.h at bs_create_bin and bs_put_integer, then inspect jit.c at jit_bitstring_insert_integer and the intn_to_integer_bytes helper. Compare the byte count passed to the helper with the integer field size, using the BEAM examples in the issue to check truncation and whether following segments remain intact. The issue is done when interpreter and JIT output matches BEAM for these cases.
Written by the indexing model from the issue text.
Description
Found while reviewing #2357; pre-existing (same code on release-0.7 at 18b35870). The interpreter and the x86_64 JIT behave the same, BEAM differs.
A byte-aligned integer segment whose value is outside the int64 range (on 64-bit builds any value >= 2^63, such as a 64-bit hash) is written with intn_to_integer_bytes(..., dst, avail) in bs_create_bin and bs_put_integer (opcodesswitch.h) and in jit_bitstring_insert_integer (jit.c), where avail is the number of bytes left in the binary, not the size of the field. The helper writes and sign-fills avail bytes and, for big-endian, reverses that whole block:
V = id(16#D2EDBB11013FBAE3), Z = id(0), X = id(5),
<<V:64, X:8>> %% BEAM <<210,237,187,17,1,63,186,227,5>> AtomVM <<0,210,237,187,17,1,63,186,5>> (value shifted by one byte)
<<V:24>> %% BEAM <<63,186,227>> AtomVM badarg (the 8-byte bignum does not fit the 3-byte binary)
<<V:16, Z:16>> %% BEAM <<186,227,0,0>> AtomVM badarg
<<V:24/little, Z:48, X:3>> %% BEAM <<227,186,63,0,0,0,0,0,0,5:3>> AtomVM <<227,186,63,1,17,187,237,210,0,5:3>> (high bytes leak into the next segment)
<<V:64>> alone is fine because the field ends the binary. The field size in bytes should be passed instead of avail, truncating the value as BEAM does. Non-byte-aligned fields are not affected: #2357 writes those through bitstring_bigint_to_field64 for values up to 64 bits.
- Dominant language
- Erlang
- Stars
- 2.3k
- Forks
- 171
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 20
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from atomvm/AtomVM
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 3 days
-
lwIP sockets: a failed listen or connect leaves the socket lock held, a later close hangs foreverOpen
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 3 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
milind-soni/OpenMausBot#5829 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
finos/fluxnova-bpm-platform#387 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
OHDSI/Data2Evidence#3693 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Project-N-E-K-O/N.E.K.O#3725 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
kubernetes-sigs/headlamp#8408 ·
Maintainers usually reply within 1 day