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

when a struct has more than one kind of empty slice whose type is pointer ,decode will panic #340

Closed
qunxu opened this issue Dec 2, 2022 · 2 comments · Fixed by #341
Closed

Comments

@qunxu
Copy link

qunxu commented Dec 2, 2022

What happened:
1.在同一个结构体里面有两种不同的指针切片的时候,如果切片两个都赋值为空切片,反序列化的时候会造成Panic。
2.在同一个结构体里面有两种不同的结构切片的时候,如果切片两个都赋值为空切片,反序列化后两个切片都会赋值为nil。
下面这段代码能复现这个结果
What you expected to happen:
1.反序列化回来两个空切片
2.反序列化回来两个空切片
How to reproduce it (as minimally and precisely as possible):

import (
hessian "github.com/apache/dubbo-go-hessian2"
)

func init() {
hessian.RegisterPOJO(new(SpPoint))
hessian.RegisterPOJO(new(Point))
hessian.RegisterPOJO(new(ReqInfo))
hessian.RegisterPOJO(new(ReqInfo2))
}

type SpPoint struct {
X int
Y int
Sp int
}

func (SpPoint) JavaClassName() string {
return "com.test.SpPoint"
}

type ReqInfo struct {
Name string
SpPoints []*SpPoint
Points []*Point
}

type ReqInfo2 struct {
Name string
SpPoints []SpPoint
Points []Point
}

func (ReqInfo2) JavaClassName() string {
return "com.test.ReqInfo2"
}

func (ReqInfo) JavaClassName() string {
return "com.test.ReqInfo"
}

func main() {
d := ReqInfo{
Name: "test",
SpPoints: []*SpPoint{},
Points: []*Point{},
}
//d := ReqInfo2{
// Name: "test",
// SpPoints: []SpPoint{},
// Points: []Point{},
//}

encoder := hessian.NewEncoder()
err := encoder.Encode(d)
if err != nil {
	return
}
decoder := hessian.NewDecoder(encoder.Buffer())
doInterface, err := decoder.Decode()

_ = doInterface

}

Anything else we need to know?:

wongoo added a commit to wongoo/hessian2 that referenced this issue Dec 4, 2022
wongoo added a commit that referenced this issue Dec 6, 2022
* fix issue #340

* format code

Co-authored-by: wongoo <wongoo@apache.org>
@tiltwind
Copy link
Contributor

tiltwind commented Dec 6, 2022

@qunxu v1.11.5 release, which fixed this issue. https://github.com/apache/dubbo-go-hessian2/releases/tag/v1.11.5

@KellendF
Copy link

Can it be compatible with previous versions? I am currently using version 1.11.0 (or pre-1.11.5 version) for encoding and version 1.11.5 for decoding, but I still encounter panic when decoding empty type pointer slices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants