Skip to content

encoding/asn1: incorrectly handles incorrect utf8 strings #11126

Closed
@dvyukov

Description

The following program crashes with "Marshal: asn1: string not valid UTF-8" panic:

package main

import "encoding/asn1"

func main() {
    data := []byte("0\x05\f\x03a\xc9c")
    v := X{}
    _, err := asn1.Unmarshal(data, &v)
    if err != nil {
        panic("Unmarshal: " + err.Error())
    }
    _, err = asn1.Marshal(v)
    if err != nil {
        panic("Marshal: " + err.Error())
    }
}

type X struct {
    S string //`asn1:"utf8"`
}

The string must either be not decoded successfully or encoded successfully.

If the utf8 tag is uncommented, then program finishes successfully. This also looks wrong as the string is not valid utf8.

on commit b0532a9

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions