Out-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.
The 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.
This 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.
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.
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.
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.
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 ..
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.
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.SMALL_TUPLE_EXT after the version byte 131.7 and NUL. Take the input as a sub-binary with binary:part/3.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.1234567890123456789012345678901 as the field and put ,5 and NUL after the input. After the call, the , byte in the parent binary is a ..An 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.
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.[safe] option to binary_to_term/2 does NOT protect against this issue. It only restricts atom creation, not structural validation of binary encodings.{
"capec_ids": [
"CAPEC-540"
],
"cpe_ids": [
"cpe:2.3:a:erlang:erlang\\/otp:*:*:*:*:*:*:*:*"
],
"cwe_ids": [
"CWE-125"
]
}