Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema can cause infinite recursion #20

Closed
rogpeppe opened this issue Jun 11, 2014 · 0 comments
Closed

schema can cause infinite recursion #20

rogpeppe opened this issue Jun 11, 2014 · 0 comments
Labels

Comments

@rogpeppe
Copy link

Parsing a recursive schema not from a URL can cause infinite recursion.

Here is a repro example. Watch out, it will tank your computer until it runs out of stack space. Putting a print inside parseSchema will cause it to be more friendly.

package main

import (
    "encoding/json"
    "log"

    "github.com/binary132/gojsonschema"
)

func main() {
    var schema map[string]interface{}
    err := json.Unmarshal(data, &schema)
    if err != nil {
        log.Fatalf("cannot unmarshal schema definition: %v", err)
    }

    _, err = gojsonschema.NewJsonSchemaDocument(schema)
    if err != nil {
        log.Fatalf("cannot parse schema definition: %v", err)
    }
}

var data = []byte(`
{
    "definitions": {
        "schemaArray": {
            "items": {
                "$ref": "#"
            },
            "type": "array"
        }
    },
    "properties": {
        "items": {
            "$ref": "#/definitions/schemaArray"
        },
        "not": {
            "$ref": "#"
        }
    },
    "type": "object"
}
`)
@xeipuuv xeipuuv added the bug label Jun 21, 2014
sigu-399 added a commit that referenced this issue Jan 3, 2015
@xeipuuv xeipuuv closed this as completed Jan 3, 2015
binary132 pushed a commit to binary132/gojsonschema that referenced this issue Jan 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants