google / google/gopacket

pcap: tests fail on windows if TestPcapFileRead runs after TestBPFInstruction

Open
#922 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

This failure can be demonstrated by either just `go test -count=2` to catch it on the second iteration, or by adding the following test and running it alone with `go test -run TestBPFInstructionThenPcapFileRead`.

```
func TestBPFInstructionThenPcapFileRead(t *testing.T) {
for _, test := range []struct {
name string
fn func(*testing.T)
}{
{"BPFInstruction", TestBPFInstruction},
{"PcapFileRead", TestPcapFileRead},
} {
t.Run(test.name, test.fn)
}
}
```

The result of either of these is
```
exit status 0xc0000374
FAIL github.com/google/gopacket/pcap 0.393s
```

Reversing the order of the tests in `TestBPFInstructionThenPcapFileRead` results in test success.

I have narrowed this down to accessing `p.data` in `*packet.packetDump`; presumably the slice here reaches beyond its allocation. At the other end of the causal chain, running `*Handle.NewBPFInstructionFilter` with a non-empty set of instructions is enough to trigger the failure.

For purposes of replicability, the npcap I am using is 1.55 (https://nmap.org/npcap/dist/npcap-1.55.exe).

```
$ go version
go version go1.17.2 darwin/amd64
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.