Skip to content

[float string]different result vs origin after call Marshal & Unmarshal #510

Closed
@hanxiatu-fc

Description

@hanxiatu-fc

testcase:
{"":[9020000000039351e-5]}

testcode:

func test(data []byte) {
	create := func() interface{} { m := map[string]interface{}{}; return &m }
	v := create()
	v1 := create()

	_ = json.Unmarshal(data, v)
	data1, _ := json.Marshal(v)
	_ = json.Unmarshal(data1, v1)

	fmt.Printf("v0: %#v, v1: %#v\n", v, v1)
}

when call test with "encoding/json" , get result:

v0: &map[string]interface {}{"":[]interface {}{9.020000000039351e+10}}, v1: &map[string]interface {}{"":[]interface {}{9.020000000039351e+10}}

when call test with json-iterator ,get result :

v0: &map[string]interface {}{"":[]interface {}{9.020000000039351e+10}}, v1: &map[string]interface {}{"":[]interface {}{9.020000000039352e+10}}

9.020000000039351e+10 vs 9.020000000039352e+10

How did I find the problem?

I refer to the test cases and test corpus for std json in the go-fuzz project to test json-iterator.

see : https://github.com/dvyukov/go-fuzz-corpus/tree/master/json

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions