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: slice is lost during marshal/unmarshal #11130

dvyukov opened this issue Jun 9, 2015 · 2 comments

encoding/asn1: slice is lost during marshal/unmarshal #11130

dvyukov opened this issue Jun 9, 2015 · 2 comments


Copy link

@dvyukov dvyukov commented Jun 9, 2015

The following program:

package main

import (

func main() {
    data := []byte("\x06\x010")
    var v interface{}
    _, err := asn1.Unmarshal(data, &v)
    if err != nil {
    data1, err := asn1.Marshal(v)
    if err != nil {
    var v1 interface{}
    _, err = asn1.Unmarshal(data1, &v1)
    if err != nil {
    if !reflect.DeepEqual(v, v1) {
        fmt.Printf("v0: %#v data=%q\n", v, data)
        fmt.Printf("v1: %#v data=%q\n", v1, data1)
        panic("not equal")


v0: []int{1, 8} data="\x06\x010"
v1: <nil> data="0\x06\x02\x01\x01\x02\x01\b"
panic: not equal

The slice should not get lost during marshal/unmarshal.

on commit b0532a9

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Jun 9, 2015
@rsc rsc modified the milestones: Unplanned, Go1.6 Nov 26, 2015
Copy link

@gopherbot gopherbot commented May 19, 2018

Change mentions this issue: encoding/asn1: fix returned type for an Object Identifier

Copy link

@iWdGo iWdGo commented May 19, 2018

Unmarshal/Marshal/Unmarshal was not idempotent as the Object Identifier type was not returned through the interface. The limit case OID = 0 returns an error. The zero OID is {0.0}

If bytes are transmitted to Marshal, a sequence of bytes is returned and not an OID and this is the intended behavior. Object Identifier is a list of int and the example submitted translates to
\x06\x010 = \x06\x01 + "0" which is OID {1,8} coded as \x06\x01\x30

@gopherbot gopherbot closed this in 6b4828a May 31, 2018
@golang golang locked and limited conversation to collaborators May 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.