Skip to content

encoding/asn1: bool values not unmarshaled into interface type #68241

Closed
@bjangelo

Description

@bjangelo

Go version

go version go1.22.3 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/bangelo/.cache/go-build'
GOENV='/home/bangelo/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/bangelo/code/go/pkg/mod'
GOOS='linux'
GOPATH='/home/bangelo/code/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=/tmp/go-build324096014=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Attempted to unmarshal boolean asn1 value into any type.

https://go.dev/play/p/QEFu_kJD6b4

package main

import (
	"encoding/asn1"
	"fmt"
	"log"
)

func main() {
	data, err := asn1.Marshal(true)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%v\n", data)

	var value any
	rest, err := asn1.Unmarshal(data, &value)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%d\n", len(rest))
	fmt.Printf("%T\n", value)
}

What did you see happen?

Unmarshal consumed the boolean TLV but did not populate the any type variable.

[1 1 255]
0
<nil>

What did you expect to see?

Unmarshal populate the any type variable.

[1 1 255]
0
bool

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions