Skip to content

Binary construction produces incorrect result #2003

@mat-hek

Description

@mat-hek

Trying to downstream FissionVM I found out that Base.decode16 (the Elixir's stdlib implementation) returns an incorrect binary. The smallest reproduction I was able to create is the following:

defmodule M do
  def process(binary) do
    process(binary, <<>>)
  end

  defp process(<<c1::8, c2::8, rest::binary>>, acc) do
    process(rest, <<acc::binary, c1::4, c2::4>>)
  end

  defp process(<<>>, acc) do
    acc
  end
end

Calling M.process("ABCDEF") returns <<21, 115, 81>>, while the correct value is <<18, 52, 86>>.

It only occurs when you enable ASAN set -fno-omit-frame-pointer, needed for ASAN:

# src/libAtomVM/CMakeLists.txt

target_compile_options(libAtomVM PUBLIC -fno-omit-frame-pointer)

and it seems it was introduced in #1906

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions