Skip to content

Panic encoding empty Any #311

Closed
Closed
@vgough

Description

@vgough

If a struct contains an Any value, and the Any value is left unset, then Marshal fails with a nil pointer dereference.

eg

package main

import (
    "fmt"

    jsoniter "github.com/json-iterator/go"
)

type Foo struct {
    A jsoniter.Any
}

func main() {
    data, _ := jsoniter.Marshal(&Foo{})
    fmt.Println(string(data))
}

The SEGV occurs here:

github.com/json-iterator/go.(*directAnyCodec).Encode(0x132e3a0, 0xc00000e990, 0xc000058180)
github.com/json-iterator/[email protected]/any.go:315 +0x29

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions