1 package main 2 3 import ( 4 "fmt" 5 "runtime" 6 "unsafe" 7 ) 8 9 func main() { 10 p := new([1024 * 1000]int) 11 p[0] = 10 12 r := bar(&p[1024*1000-1]) 13 fmt.Printf("r value is %d", r) 14 } 15 16 func bar(a *int) int { 17 p := unsafe.Add(unsafe.Pointer(a), 2*unsafe.Sizeof(int(1))) 18 runtime.ASanWrite(p, 8) // BOOM 19 *((*int)(p)) = 10 20 return *((*int)(p)) 21 } 22