V3: Clang ASan heap-buffer-overflow when dispatching u8-backed enum boxed as interface

Open
#32,716 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
22/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c
Domain
compilers

Research direction

Start with the ASan failure in vlib/v/tests/interfaces/interface_enum_and_fixed_array_values_test.v (test_enum_method_dispatch) and reduce it to Namer(Small.b).name() for a u8-backed enum. Compare the box allocation size with the enum storage width in vlib/v/transform/interface.v (make_interface_literal_from_expr) and vlib/v/gen/c/interface.v (gen_interface_dispatch_with_fallback, interface_concrete_storage_c_type). Done means the 1-byte enum interface case passes under the exact clang -fsanitize=address command without suppressions or larger allocations.

Written by the indexing model from the issue text.

Description

Executed historical master failure (not a queued-job inference)

  • Failing master d8083d40873efc7689abdb15f4ca21b4f5d59f4a, completed November 21, 2026, 22:22 UTC: Clang ASan-no-GC job 136897142301.
  • After 4,180 executed passes / 693 skips, exactly one vlib/v/tests/interfaces/interface_enum_and_fixed_array_values_test.v failure: test_enum_method_dispatch. Original invocation:
    ./v -cc clang -gc none -cflags -fno-omit-frame-pointer -cflags -fsanitize=address -silent vlib/v/tests/interfaces/interface_enum_and_fixed_array_values_test.v
  • ASan: READ of size 4 in Namer__name, through test_enum_method_dispatch, from a 1-byte memdup allocation created by the same test. Heap address 0x602000000090, region [0x602000000090,0x602000000091); read extends into the right redzone. This is a real generated-code memory-safety error, not a deliberately failing fixture, test harness timeout, or external-library sanitizer trace.

Minimal source discriminator

The test includes enum Small as u8 { a = 3; b = 200 }, fn (s Small) name() string, and assert Namer(Small.b).name() == 'small:b'. That 1-byte allocation strongly implicates the boxed Small value; the exact mismatched generated C cast is not yet established. Color and Perm also implement Namer with ordinary-width enum storage. The full fixture has the same blob 770b736ace758bf52c83b03fe64360f0d6413e76 on failing d808 and current master 9621aa02fd7d7788700846e93242d08bd70a8aea.

Relevant code for checking both sides of the ABI:

  • vlib/v/transform/interface.v: make_interface_literal_from_expr, especially box concrete_type, make_sizeof_type(concrete_type), and the _object pointer/type registration (around 973–1154).
  • vlib/v/gen/c/interface.v: gen_interface_dispatch_with_fallback (around 1815–2011), interface_dispatch_receiver_expr (around 118–175), interface_concrete_storage_c_type (around 2393–2413), interface_method_call_cname and types.Enum handling.
  • Existing merged PR #30879 added enum/interface dispatch tests and type tags, but does not establish this ASan size mismatch was corrected.

Required repair/verification

  1. Reduce to Namer(Small.b).name() alone, box_namer(Small.b).name(), direct Small.b.name(), plus the same enum with as int, and inspect ./v -keepc -cg -cc clang generated C: compare allocated sizeof, enum typedef/storage width, Namer__name branch _typ, selected receiver cast, and Small__name declaration.
  2. Rebuild V after a minimal proven type-registration/ABI correction; require all relevant widths to agree, not an increased allocation or sanitizer suppression without evidence. Add an explicit 1-byte enum interface regression preserving existing checks.
  3. Re-run the exact Clang ASan command above on a fixed descendant plus GCC ASan and normal Clang/GCC, original complete interface_enum_and_fixed_array_values_test.v, V fmt/self checks.

Status: unresolved / still applicable by unchanged test and present boxing/dispatch code. No native V toolchain was available in the current investigation environment; no generated-C proof or patched native test is claimed.

[!NOTE]
You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Dominant language
V
Stars
38.1k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
682

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vlang/v

All issues in vlang/v

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.