ASan: translated fixed [9]i8 struct field reads 9 bytes from c'local' (6-byte C literal)

Open
#32,706 2 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
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c
Domain
compilers

Research direction

Start with vlib/v/gen/c/struct.v, in gen_struct_init_with_fixed_array_fields_impl and write_fixed_field_copy, and check why gen_fixed_array_copy_source falls back to sizeof(destination) for short c'...' literals. Reproduce with ./v -cc gcc -cflags -fsanitize=address -silent vlib/v/tests/translated_c_string_fixed_char_array_struct_init_test.v after ./v self, and inspect the output of -keepc. Done when that test passes under GCC and Clang ASan with the assertions unchanged and a regression test added.

Written by the indexing model from the issue text.

Description

Executed master CI failure (R363)

Master d8083d40873efc7689abdb15f4ca21b4f5d59f4a — GCC ASan vlib shard 2, job 136897142365, completed 2026-11-21 18:35 UTC while the parent workflow was still queued. After 1,270 passed / 186 skipped, the executed vlib/v/tests/translated_c_string_fixed_char_array_struct_init_test.v failed test_translated_c_string_initializes_local_fixed_char_array_fields with AddressSanitizer global-buffer-overflow: memcpy READ9 immediately after 6-byte global literal "local". This is a Cgen/runtime memory-safety error, not a timeout, setup failure, or intentional failing fixture.

Reproduce the original hosted command: ./v -cc gcc -cflags -fno-omit-frame-pointer -cflags -fsanitize=address -silent vlib/v/tests/translated_c_string_fixed_char_array_struct_init_test.v.

Source and suspected mechanism

The entire fixture is byte-identical between failing SHA and the inspected 4b4f8c2b master (blob 422e50865e1658117e24bc560b9111df6a22edab). It sets short_name: c'local' in FixedNames where SignedNameAlias = [9]i8, and asserts indices 4 and 5 (l, NUL). vlib/v/gen/c/struct.v gen_struct_init_with_fixed_array_fields_impl emits per-field copies using write_fixed_field_copy; that function is designed to copy min(sizeof(C string literal), sizeof(destination)) for a bare quoted source, but defaults to sizeof(destination) for all other emitted expressions. A cast/wrapper from signed-char or alias lowering, or another Cgen branch, could bypass its literal detection. The precise generated C source was not retained in the job; that discriminator remains unproved.

Local discriminator (C-only, not V validation)

I independently compiled a GCC14 C11/ASan analogue. memcpy(short_name, "local", sizeof(short_name)) (9 bytes) produced the same global-buffer-overflow READ9 and exit1; limiting the copy to min(sizeof("local"), sizeof(short_name)) passed exit0. This demonstrates the C memory rule but does not validate V's generated C, type/alias recognition, or a compiler patch.

Required correction and validation

  1. Rebuild current ./v self, inspect -keepc -cg output for the original fixture; print both the original AST value node kind/type and gen_fixed_array_copy_source rendered expression, and determine why the literal-size branch is bypassed.
  2. Correct only the applicable Cgen path so short c'...' literals zero-pad fixed [N]i8/char/u8 struct fields, even through aliases/wrappers; do not trim raw fixed-array expressions whose full size is known. Preserve all existing fixture assertions and exact/UTF-8/escaped/heap/global cases; add a regression for the precise transformed source shape.
  3. Repeat the original GCC ASan command, Clang ASan, focused V test/format, and ./v self on the patched revision. No disabling the sanitizer, skipping the test, or weakening assertions.

Status UNRESOLVED / STILL APPLICABLE. No overlap found in searched existing PRs/issues for this exact executed fixture, no V toolchain available locally, no speculative merge.

[!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.