From b6ec56bc26a89e9733390dd41fade5baace5a641 Mon Sep 17 00:00:00 2001 From: Romain Baugue Date: Wed, 1 May 2019 14:52:57 +0200 Subject: encoding/json: don't indirect pointers when decoding null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The indirect method checked the type of the child when indirecting a pointer. If the current value is a pointer and we are decoding null, we can skip this entirely and return early, avoiding the whole descent. Fixes #31776 Change-Id: Ib8b2a2357572c41f56fceac59b5a858980f3f65e Reviewed-on: https://go-review.googlesource.com/c/go/+/174699 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí --- src/encoding/json/decode_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/encoding/json/decode_test.go') diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go index 72d384a80f..489f8674d0 100644 --- a/src/encoding/json/decode_test.go +++ b/src/encoding/json/decode_test.go @@ -401,6 +401,11 @@ type B struct { B bool `json:",string"` } +type DoublePtr struct { + I **int + J **int +} + var unmarshalTests = []unmarshalTest{ // basic types {in: `true`, ptr: new(bool), out: true}, @@ -656,6 +661,11 @@ var unmarshalTests = []unmarshalTest{ err: fmt.Errorf("json: unknown field \"X\""), disallowUnknownFields: true, }, + { + in: `{"I": 0, "I": null, "J": null}`, + ptr: new(DoublePtr), + out: DoublePtr{I: nil, J: nil}, + }, // invalid UTF-8 is coerced to valid UTF-8. { -- cgit v1.3