wk8 / go-ordered-map

Optimal implementation of ordered maps for Golang - ie maps that remember the order in which keys were inserted.
Apache License 2.0
534 stars 40 forks source link

Fuzz un/marshall-ing methods after #16 #19

Closed fenollp closed 1 year ago

fenollp commented 1 year ago

Run fuzzing with go test -fuzz=. -fuzztime=10s ./...

--- FAIL: FuzzMarshalling (0.00s)
    --- FAIL: FuzzMarshalling/8093511184ad3e258aa13b957e75ff26c7fae64672dae0c0bc0a9fa5b61a05e7 (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x610968]

goroutine 7 [running]:
testing.tRunner.func1.2({0x63f4e0, 0x84be00})
    /snap/go/10008/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
    /snap/go/10008/src/testing/testing.go:1399 +0x39f
panic({0x63f4e0, 0x84be00})
    /snap/go/10008/src/runtime/panic.go:884 +0x212
encoding/json.(*encodeState).marshal.func1()
    /snap/go/10008/src/encoding/json/encode.go:327 +0x6e
panic({0x63f4e0, 0x84be00})
    /snap/go/10008/src/runtime/panic.go:884 +0x212
github.com/bahlo/generic-list-go.(*List[...]).Front(...)
    /home/pete/wefwefwef/go/pkg/mod/github.com/bahlo/generic-list-go@v0.2.0/list.go:70
github.com/wk8/go-ordered-map/v2.(*OrderedMap[...]).Oldest(...)
    /home/pete/wefwefwef/go-ordered-map.git/orderedmap.go:102
github.com/wk8/go-ordered-map/v2.(*OrderedMap[...]).MarshalJSON(0xc000069270)
    /home/pete/wefwefwef/go-ordered-map.git/json.go:23 +0x88
encoding/json.marshalerEncoder(0xc00015e600, {0x66f160?, 0xc000069270?, 0x30?}, {0x8?, 0x31?})
    /snap/go/10008/src/encoding/json/encode.go:478 +0xbe
encoding/json.(*encodeState).reflectValue(0x0?, {0x66f160?, 0xc000069270?, 0x40ef87?}, {0x78?, 0x0?})
    /snap/go/10008/src/encoding/json/encode.go:359 +0x78
encoding/json.(*encodeState).marshal(0x88?, {0x66f160?, 0xc000069270?}, {0x80?, 0xf6?})
    /snap/go/10008/src/encoding/json/encode.go:331 +0xfa
encoding/json.Marshal({0x66f160, 0xc000069270})
    /snap/go/10008/src/encoding/json/encode.go:160 +0x45
github.com/wk8/go-ordered-map/v2.FuzzMarshalling.func1(0x0?, {0xc00001cc60, 0x2, 0x8})
    /home/pete/wefwefwef/go-ordered-map.git/fuzz_test.go:31 +0x1b4
reflect.Value.call({0x634b40?, 0x6ab2a8?, 0x13?}, {0x67d806, 0x4}, {0xc0001097d0, 0x2, 0x2?})
    /snap/go/10008/src/reflect/value.go:584 +0x8c5
reflect.Value.Call({0x634b40?, 0x6ab2a8?, 0x51b?}, {0xc0001097d0?, 0x7ee0d8?, 0x825900?})
    /snap/go/10008/src/reflect/value.go:368 +0xbc
testing.(*F).Fuzz.func1.1(0x0?)
    /snap/go/10008/src/testing/fuzz.go:337 +0x231
testing.tRunner(0xc000134b60, 0xc000136090)
    /snap/go/10008/src/testing/testing.go:1446 +0x10b
created by testing.(*F).Fuzz.func1
    /snap/go/10008/src/testing/fuzz.go:324 +0x5b9
exit status 2
FAIL    github.com/wk8/go-ordered-map/v2    0.006s
wk8 commented 1 year ago

@fenollp : allowed lazy-init for JSON unmarshalling in v2.1.2, see for example this test => https://github.com/wk8/go-ordered-map/blob/v2.1.2/json_test.go#L138-L199

I'll have another look at this PR in the next few days, it'd still be great to add it to make sure the JSON handling is solid.

wk8 commented 1 year ago

Thanks for the patch, this is great :)

fenollp commented 1 year ago

Thanks for your time!