Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/asn1: cannot unmarshal SET if its fields have different ordering #19873

Open
hirochachacha opened this issue Apr 7, 2017 · 1 comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hirochachacha
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

package main

import (
	"encoding/asn1"
	"fmt"
)

type A struct {
	Name string
	Int  int
}

type B struct {
	Int  int
	Name string
}

func main() {
	bs, err := asn1.Marshal(A{Name: "foo", Int: 5})
	if err != nil {
		panic(err)
	}

	bs[0] = asn1.TagSet | 0x20

	var b B

	rest, err := asn1.UnmarshalWithParams(bs, &b, "set")
	if err != nil {
		panic(err)
	}
	if len(rest) != 0 {
		panic("invalid length")
	}

	fmt.Println(b)
}

What did you expect to see?

{5 foo}

What did you see instead?

panic: asn1: structure error: tags don't match (2 vs {class:0 tag:19 length:3 isCompound:false}) {optional:false explicit:false application:false defaultValue: tag: stringType:0 timeType:0 set:false omitEmpty:false} int @2

goroutine 1 [running]:
main.main()
/Users/hiro/set.go:42 +0x24a
exit status 2

Does this issue reproduce with the latest release (go1.8)?

yes

System details

go version devel +5cadc91b3c Tue Apr 4 02:40:11 2017 +0000 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hiro/.go"
GORACE=""
GOROOT="/Users/hiro/go"
GOTOOLDIR="/Users/hiro/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wq/dwn8hs0x7njbzty9f68y61700000gn/T/go-build019140017=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOROOT/bin/go version: go version devel +5cadc91b3c Tue Apr 4 02:40:11 2017 +0000 darwin/amd64
GOROOT/bin/go tool compile -V: compile version devel +5cadc91b3c Tue Apr 4 02:40:11 2017 +0000 X:framepointer
uname -v: Darwin Kernel Version 16.5.0: Fri Mar  3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.12.4
BuildVersion:	16E195
lldb --version: lldb-370.0.37
  Swift-3.1
gdb --version: GNU gdb (GDB) 7.12.1
@bradfitz bradfitz added this to the Unplanned milestone Apr 7, 2017
@bradfitz bradfitz added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 7, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Apr 7, 2017

I'm not sure whether this is a bug, but even if it is, I think encoding/asn1 is on life support and mostly frozen. It exists in the standard library just to serve crypto/tls via crypto/x509.

I'll let @agl decide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants