-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed as not planned
Labels
Milestone
Description
What version of Go are you using (go version)?
go version go1.11.2 linux/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env)?
go env Output
$ go envgo env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build954256754=/tmp/go-build -gno-record-gcc-switches"
What did you do?
A simple test case to illustrate the problem:
package main
import (
"bytes"
"errors"
"io"
"io/ioutil"
"testing"
"golang.org/x/crypto/openpgp"
)
const (
pass = "passwordok"
wrongPass = "passwordfailed"
message = "hello world"
)
var noSymmetric = errors.New("Symmetric not set")
func TestHelloWorld(t *testing.T) {
var out = bytes.Buffer{}
var in = bytes.NewReader([]byte(message))
w, err := openpgp.SymmetricallyEncrypt(&out, []byte(pass), nil, nil)
if err != nil {
t.Fatal(err)
}
if _, err = io.Copy(w, in); err != nil {
t.Fatal(err)
}
if err := w.Close(); err != nil {
t.Fatal(err)
}
encryptedSrc := bytes.NewReader(out.Bytes())
md, err := openpgp.ReadMessage(encryptedSrc, nil, func(keys []openpgp.Key, symmetric bool) ([]byte, error) {
if !symmetric {
return nil, noSymmetric
}
return []byte(wrongPass), nil
}, nil)
if err != nil {
t.Fatal(err)
}
content, err := ioutil.ReadAll(md.UnverifiedBody)
if err != nil {
t.Fatal(err)
}
if string(content) != message {
t.Fatalf("Expected %s actual %s", message, content)
}
}What did you expect to see?
An error should be returned from ReadMessage
What did you see instead?
An infinite loop.
nasa9084 and sashabaranovexcavador