• Kubernetes Submit Queue's avatar
    Merge pull request #38525 from juanvallejo/jvallejo/fix-panic-on-invalid-json-syntax · 36c20d1f
    Kubernetes Submit Queue authored
    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
    36c20d1f
Name
Last commit
Last update
..
schema Loading commit data...
serializer Loading commit data...
BUILD Loading commit data...
OWNERS Loading commit data...
codec.go Loading commit data...
codec_check.go Loading commit data...
conversion.go Loading commit data...
conversion_test.go Loading commit data...
doc.go Loading commit data...
embedded.go Loading commit data...
embedded_test.go Loading commit data...
error.go Loading commit data...
extension.go Loading commit data...
extension_test.go Loading commit data...
generated.pb.go Loading commit data...
generated.proto Loading commit data...
helper.go Loading commit data...
helper_test.go Loading commit data...
interfaces.go Loading commit data...
register.go Loading commit data...
scheme.go Loading commit data...
scheme_builder.go Loading commit data...
scheme_test.go Loading commit data...
swagger_doc_generator.go Loading commit data...
swagger_doc_generator_test.go Loading commit data...
types.go Loading commit data...
types_proto.go Loading commit data...
unversioned_test.go Loading commit data...
zz_generated.deepcopy.go Loading commit data...