kubernetes/pkg/runtime/serializer
Kubernetes Submit Queue 36c20d1f5e Merge pull request #38525 from juanvallejo/jvallejo/fix-panic-on-invalid-json-syntax
Automatic merge from submit-queue (batch tested with PRs 38525, 38977)

Prevent json decoder panic on invalid input

Related downstream issue: https://github.com/openshift/origin/issues/12132
```
# Can be replicated on kubectl with:
$ cat panic.json
{
  "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "name": "",
    "labels": {
      "name": ""
    },
    "generateName": "",
    "namespace": "",
    "annotations": []
  },
  "spec": {}
},

$ kubectl create -f panic.json --validate=false
```

**Release note**:
```release-note
release-note-none
```

This patch handles cases where `ioutil.ReadAll` will return a single
character output on an invalid json input, causing the `Decode` method
to panic when it tries to calculate the line number for the syntax
error. The example below would cause a panic due to the trailing comma
at the end:

```
{
  "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "name": "",
    "labels": {
      "name": ""
    },
    "generateName": "",
    "namespace": "",
    "annotations": []
  },
  "spec": {}
},
```

@kubernetes/cli-review @fabianofranz
2016-12-19 13:23:03 -08:00
..
json Merge pull request #38525 from juanvallejo/jvallejo/fix-panic-on-invalid-json-syntax 2016-12-19 13:23:03 -08:00
protobuf autoupdate BUILD files 2016-12-12 13:30:07 -08:00
recognizer autoupdate BUILD files 2016-12-12 13:30:07 -08:00
streaming autoupdate BUILD files 2016-12-12 13:30:07 -08:00
versioning autoupdate BUILD files 2016-12-12 13:30:07 -08:00
yaml autoupdate BUILD files 2016-12-12 13:30:07 -08:00
BUILD autoupdate BUILD files 2016-12-12 13:30:07 -08:00
codec_factory.go let DirectEncoder take a hint of what gvk to set during its construction 2016-12-07 14:17:34 -08:00
codec_test.go refactor: generated 2016-12-03 19:10:46 -05:00
negotiated_codec.go Replace negotiation with a new method that can extract info 2016-10-28 11:30:11 -04:00
protobuf_extension.go Replace negotiation with a new method that can extract info 2016-10-28 11:30:11 -04:00