When an atom is first used, it is assigned an internal number and placed in an array in a virtual machine. This array is distributed statically and can be filled if sufficiently different atoms are used. binary_to_existing_atom will only convert a binary string to an atom that already exists in the array, if it does not exist, the call will fail.
If you convert the input directly to atoms without any sanity checks, the external client can send <<"a" → and <"b" → until the array is full, at which point vm fails.
Another way to avoid this is to simply not use binary_to_atom and instead match patterns in different binaries and return the desired atom.
Lukas source share