1// Copyright 2016 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build amd64 && (linux || darwin)
6
7package sha1_test
8
9import (
10	"crypto/sha1"
11	"syscall"
12	"testing"
13)
14
15func TestOutOfBoundsRead(t *testing.T) {
16	const pageSize = 4 << 10
17	data, err := syscall.Mmap(0, 0, 2*pageSize, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
18	if err != nil {
19		panic(err)
20	}
21	if err := syscall.Mprotect(data[pageSize:], syscall.PROT_NONE); err != nil {
22		panic(err)
23	}
24	for i := 0; i < pageSize; i++ {
25		sha1.Sum(data[pageSize-i : pageSize])
26	}
27}
28