{"id":"EEF-CVE-2026-120961","summary":"binary_to_term Heap Overrun via FLOAT_EXT Without Terminating Zero Byte May Abort the VM","details":"## Summary\n\nOut-of-bounds Read vulnerability in the external term format decoder in Erlang OTP erts allows an attacker who controls the input to `binary_to_term/1,2` to read memory after the input, and to change one byte there, via a `FLOAT_EXT` term without a terminating zero byte. `decoded_size` in `erts/emulator/beam/external.c` checks only that the 31 bytes of the `FLOAT_EXT` field are present. `dec_term` then passes the field to `sys_chars_to_double`, which scans to a NUL byte without a length limit. When the field has no NUL, the scan continues into the bytes after the field, and those bytes change the decoded float. When the radix character is found after the field and `strtod` does not accept it, `sys_chars_to_double` overwrites that byte (a `,` becomes a `.`). The VM can fault if the scan reaches an unmapped page.\n\nThe `safe` option does not prevent this. `enif_binary_to_term()` and the distribution protocol reach the same decoder, and distribution is assumed to run on trusted networks only. The write is limited to the one radix byte. No arbitrary write or code execution was shown.\n\nThis issue affects OTP from OTP 17.0 before OTP 27.3.4.20, OTP 28.5.0.9, and OTP 29.1.3, corresponding to erts from 6.0 before 15.2.7.15, 16.4.0.8, and 17.1.2. Whether OTP before OTP 17.0, corresponding to erts before 6.0, is affected is unknown.\n\n## Details\n\n**1. Size pass.** `binary_to_term_int` first calls `decoded_size` in `erts/emulator/beam/external.c`. For `FLOAT_EXT` (tag 99), `decoded_size` skips 31 bytes and reserves heap for one float. It does not examine the content of the field.\n\n**2. Decode pass.** `dec_term` passes the pointer to the field to `sys_chars_to_double` and then advances by 31 bytes. The call carries no length. `sys_chars_to_double` (in `erts/emulator/sys/unix/sys_float.c` and `erts/emulator/sys/win32/sys_float.c`) treats the field as a C string.\n\n**3. Out-of-bounds read.** `sys_chars_to_double` checks the float syntax one character at a time and requires a NUL after the last digit. A valid encoder pads the field with NUL bytes. When all 31 bytes are part of a float, the scan and the subsequent `strtod` call continue into the bytes after the field. When the field is the last term of the input, these are bytes after the input. If they complete a valid float and a NUL follows, the decoded value contains them.\n\n**4. One-byte write.** `sys_chars_to_double` remembers the position of the radix character, which can be `.` or `,`. If `strtod` stops before the end of the scanned string, the function replaces the radix character with the other one in place and calls `strtod` again. When the field contains only digits, the radix character is a byte after the field. A `,` there is changed to `.`.\n\n**5. Fault.** The scan has no upper limit. If only digits follow up to the end of the mapped memory, the read faults and the VM aborts.\n\n## Proof of concept\n\n1. Build a `FLOAT_EXT` field without a NUL byte: tag 99 followed by the 31 bytes `1.0e` plus 26 times `0` plus `1`. This is the float 10.0.\n2. Put the field at the end of an input, for example as the last element of a `SMALL_TUPLE_EXT` after the version byte 131.\n3. Build a larger binary that holds the input followed by the bytes `7` and NUL. Take the input as a sub-binary with `binary:part/3`.\n4. Call `binary_to_term/2` with `[safe]` on the sub-binary. The last element decodes as `1.0e17` and not `10.0`: the decoder read the `7` after the input.\n5. For the write, use the 31 digits `1234567890123456789012345678901` as the field and put `,5` and NUL after the input. After the call, the `,` byte in the parent binary is a `.`.\n\n## Impact\n\nAn attacker who can supply bytes to `binary_to_term/1,2` or `enif_binary_to_term()` can make the decoder read bytes after the input, which then change the decoded float, and can change one `,` byte after the input to `.`. The VM can abort if the read reaches unmapped memory.\n\n## Workarounds\n\n* Do not call `binary_to_term/1,2` on data from untrusted sources. The OTP Secure Coding Guidelines (DSG-011) recommend avoiding these functions altogether on untrusted data.\n* If distribution is exposed to untrusted networks, configure it to use TLS with client certificate verification.\n* Use alternative serialization formats (JSON, Protocol Buffers) for untrusted external input.\nNote: the `[safe]` option to `binary_to_term/2` does NOT protect against this issue. It only restricts atom creation, not structural validation of binary encodings.","aliases":["GHSA-r7pf-rpq8-5pf4","CVE-2026-120961"],"modified":"2026-11-24T15:15:03.845166625Z","published":"2026-11-24T15:10:40.813Z","database_specific":{"cwe_ids":["CWE-125"],"capec_ids":["CAPEC-540"],"cpe_ids":["cpe:2.3:a:erlang:erlang\\/otp:*:*:*:*:*:*:*:*"]},"references":[{"type":"ADVISORY","url":"https://github.com/erlang/otp/security/advisories/GHSA-r7pf-rpq8-5pf4"},{"type":"WEB","url":"https://cna.erlef.org/cves/CVE-2026-120961.html"},{"type":"WEB","url":"https://www.erlang.org/doc/system/versions.html#order-of-versions"},{"type":"FIX","url":"https://github.com/erlang/otp/commit/4b954b8aa0f601a0d8d45f0953c77585afb6f853"}],"affected":[{"ranges":[{"type":"GIT","repo":"https://github.com/erlang/otp","events":[{"introduced":"84adefa331c4159d432d22840663c38f155cd4c1"},{"fixed":"4b954b8aa0f601a0d8d45f0953c77585afb6f853"}]}],"versions":["patch-base-27","OTP-27.3.4","OTP-27.0","OTP-27.3","OTP-27.3.3","OTP-26.0","OTP-25.0","OTP-27.3.2","OTP-27.2","OTP-27.3.1","OTP-27.1","OTP-27.0-rc3","OTP-27.0-rc2","OTP-27.0-rc1","OTP-24.0","OTP-26.0-rc3","OTP-26.0-rc2","OTP-26.0-rc1","OTP-23.0","OTP-21.0","OTP-25.0-rc3","OTP-25.0-rc2","OTP-25.0-rc1","OTP-22.0","OTP-24.0-rc3","OTP-24.0-rc2","OTP-24.0-rc1","OTP-23.0-rc3","OTP-23.0-rc2","OTP-23.0-rc1","OTP-20.0","OTP-22.0-rc3","OTP-22.0-rc2","OTP-22.0-rc1","OTP-19.0","OTP-21.0-rc2","OTP-18.0","OTP-21.0-rc1","OTP-17.0","OTP-20.0-rc2","OTP-20.0-rc1","OTP-19.0-rc2","OTP-19.0-rc1","OTP_R16B","OTP-18.0-rc1","OTP_17.0-rc2","OTP_17.0-rc1","OTP_R13B03","OTP_R16A_RELEASE_CANDIDATE","OTP_R14B03","OTP_R15B","OTP_R15A","OTP_R14B02","OTP_R14B01","OTP_R14B","OTP_R13B04","OTP_R14A"],"database_specific":{"source":"https://cna.erlef.org/osv/EEF-CVE-2026-120961.json"}}],"schema_version":"1.9.2","severity":[{"type":"CVSS_V4","score":"CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","source":"CNA"}],"credits":[{"name":"Khaled Suliman","type":"FINDER"},{"name":"Khaled Suliman","type":"REPORTER"},{"name":"Jonatan Männchen / EEF","type":"COORDINATOR"}]}