Skip to content

-fsanitize=object-size reports out-of-bounds access as misaligned access #96333

Open
@davidben

Description

If building the following with -fsanitize=object-size, the sanitizer correctly flags the code as UB...

#include <stddef.h>

void ReadValueOutOfArrayBoundsRight(char *ptr, size_t size) {
  char c = ptr[size + 1];
}

int main() {
  char foo[16];
  ReadValueOutOfArrayBoundsRight(foo, 16);
}

https://godbolt.org/z/e4oWfYdPG

However, the error it outputs is:

/app/example.cpp:4:12: runtime error: load of misaligned address 0x7ffcd4609ba1 for type 'char', which requires 2 byte alignment

This does not make sense because char does not require 2 byte alignment, and indeed the alignment is just fine. It's just out of bounds.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions