Skip to content

[Go] Panic when deserializing serialized pointer of struct using WithCompatible #3039

@shanipribadi

Description

@shanipribadi

Search before asking

  • I had searched in the issues and found no similar issues.

Version

require github.com/apache/fory/go/fory v0.0.0-20251210114924-170ff49a1cc4
go version go1.25.4 linux/amd64

Component(s)

Go

Minimal reproduce step

func main() {
        f := fory.New(
                fory.WithCompatible(true),
        )
        type A struct {
                Name string
        }

        f.RegisterNamedType(A{}, "test.A")
        a := A{Name: "hello"}
        buf, err := f.Marshal(&a)
        if err != nil {
                log.Fatalf("err: %v", err)
        }
        log.Printf("buf: % x", buf)
        b := A{}
        err = f.Unmarshal(buf, &b)
        if err != nil {
                log.Fatalf("err: %v", err)
        }
        log.Printf("b: %v", b)
}

What did you expect to see?

working deserialization

What did you see instead?

panic: runtime error: slice bounds out of range [:86073] with capacity 138

Anything Else?

changing the struct into

struct A {
FirstName string
LastName string
}

gives panic: invalid string encoding: 3

changing the struct into

struct A {
FirstName string
}

doesn't actually cause a panic, but somehow the result is wrong

Marshaling the struct directly instead of pointer actually works

        buf, err := f.Marshal(a)
        err = f.Unmarshal(buf, &b)

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions