Skip to content

illegal read of byte preceding an automatic (stack allocate) variable #73718

Closed
@RobertHenry6bev

Description

@RobertHenry6bev

Description

Compiling on/for x64 architecture on linux with clang-14.

The function CMiniMdBase::InitColsForTable

CMiniColDef pCols[9]; // The col defs to init.

allocates an automatic array variable of CMiniColDef[9]. The base address of this array is passed down through UsesAllocatedMemory(). UsesAllocatedMemory apparently implements some kind of marking of the preceding byte to determine if the block was obtained from a memory allocator.

But in this case, the block is an automatic in some nearby frame. In our case, the preceding bytes contain a pointer pTemplate. Uses AllocatedMemory reads a byte from that pointer, which one depends on endianness.

You can't do thatt.

Reproduction Steps

Compile with -fsanitize=address and stop at first fail.

Expected behavior

no errors detected by asan

Actual behavior

Read an adjacent memory location.

Regression?

No response

Known Workarounds

Probably put a dummy slot in the frame before the [9] vector to emulate what's done when those CMiniColDefs are allocated dynamically.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions