santhosh-tekuri/jsonschema

Invalid pointer found on stack

Closed this issue · 6 comments

When calling jsonschema.Compile() with a particular schema, I get a stack trace. I've been able to successfully call jsonschema.Compile() with other schemas.

Go Version: 1.10.1 darwin/amd64

Schema:
I used https://www.jsonschemavalidator.net/ to validate that this schema does not have errors.

{
    "schema": "http://json-schema.org/schema#",
    "title": "Tag Action",
    "type": "object",
    "properties": {
        "tags": {
            "description": "The tags to be added to the alert.",
            "type": "array",
            "items": {
                "description": "A single tag to be added to the alert.",
                "type": "string"
            }
        }
    },
    "required": ["tags"]
}

My Code:

func LoadAndValidateJSONConfig(schemaFileName string, configFileName string, destinationStruct interface{}) error {
	schema, err := jsonschema.Compile(schemaFileName)
	if err != nil {
		return errors.Wrap(err, fmt.Sprintf("Error compiling JSON schema \"%s\"", schemaFileName))
	}

	f, err := os.Open(configFileName)
	if err != nil {
		return errors.Wrap(err, fmt.Sprintf("Error opening config file \"%s\" for verification", configFileName))
	}
	defer f.Close()

	if err = schema.Validate(f); err != nil {
		return errors.Wrap(err, "Error while validating config against the provided schema")
	}

	return LoadJSONConfig(configFileName, destinationStruct)
}

Trace:

runtime: bad pointer in frame github.com/santhosh-tekuri/jsonschema.(*Schema).validate at 0xc4201d4b78: 0x4
fatal error: invalid pointer found on stack

runtime stack:
runtime.throw(0x635b987, 0x1e)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/panic.go:616 +0x81 fp=0x7ffeefbfebe0 sp=0x7ffeefbfebc0 pc=0x602aea1
runtime.adjustpointers(0xc4201d4230, 0x7ffeefbfecd8, 0x7ffeefbff098, 0x64cf008, 0x64e0560)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/stack.go:592 +0x23e fp=0x7ffeefbfec50 sp=0x7ffeefbfebe0 pc=0x604175e
runtime.adjustframe(0x7ffeefbfefa8, 0x7ffeefbff098, 0x64e0560)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/stack.go:663 +0x325 fp=0x7ffeefbfed08 sp=0x7ffeefbfec50 pc=0x6041aa5
runtime.gentraceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc420000180, 0x0, 0x0, 0x7fffffff, 0x636b508, 0x7ffeefbff098, 0x0, ...)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/traceback.go:310 +0x12d3 fp=0x7ffeefbff010 sp=0x7ffeefbfed08 pc=0x604b2b3
runtime.copystack(0xc420000180, 0x10000, 0x7ffeefbff201)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/stack.go:891 +0x26e fp=0x7ffeefbff1c8 sp=0x7ffeefbff010 pc=0x604258e
runtime.newstack()
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/stack.go:1063 +0x310 fp=0x7ffeefbff358 sp=0x7ffeefbff1c8 pc=0x60429a0
runtime.morestack()
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/asm_amd64.s:480 +0x89 fp=0x7ffeefbff360 sp=0x7ffeefbff358 pc=0x6052989

goroutine 1 [copystack]:
github.com/santhosh-tekuri/jsonschema.(*Schema).validate(0xc420160000, 0x42d6100, 0xc42015ab70, 0x0, 0x0)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:144 +0x4b70 fp=0xc4201d2748 sp=0xc4201d2740 pc=0x629a380
github.com/santhosh-tekuri/jsonschema.(*Schema).validate(0xc420153b80, 0x42d6100, 0xc42015ab70, 0x1a, 0x0)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:153 +0x4895 fp=0xc4201d33b8 sp=0xc4201d2748 pc=0x629a0a5
github.com/santhosh-tekuri/jsonschema.(*Schema).validate(0xc420153900, 0x42d6100, 0xc42015ab70, 0x4, 0xc4201c4758)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:225 +0x3c1 fp=0xc4201d4028 sp=0xc4201d33b8 pc=0x6295bd1
github.com/santhosh-tekuri/jsonschema.(*Schema).validate(0xc420152280, 0x42f1a60, 0xc42013df80, 0x0, 0x0)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:304 +0x30e4 fp=0xc4201d4c98 sp=0xc4201d4028 pc=0x62988f4
github.com/santhosh-tekuri/jsonschema.(*Schema).validate(0xc420152a00, 0x42f1a60, 0xc42013df80, 0x0, 0x0)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:153 +0x4895 fp=0xc4201d5908 sp=0xc4201d4c98 pc=0x629a0a5
github.com/santhosh-tekuri/jsonschema.(*Schema).validate(0xc420152780, 0x42f1a60, 0xc42013df80, 0x5, 0xc4201c4648)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:225 +0x3c1 fp=0xc4201d6578 sp=0xc4201d5908 pc=0x6295bd1
github.com/santhosh-tekuri/jsonschema.(*Schema).validate(0xc420152280, 0x42f1a60, 0xc42013df50, 0x0, 0x0)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:304 +0x30e4 fp=0xc4201d71e8 sp=0xc4201d6578 pc=0x62988f4
github.com/santhosh-tekuri/jsonschema.(*Schema).validate(0xc420165b80, 0x42f1a60, 0xc42013df50, 0x4, 0xc4201c4868)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:153 +0x4895 fp=0xc4201d7e58 sp=0xc4201d71e8 pc=0x629a0a5
github.com/santhosh-tekuri/jsonschema.(*Schema).validate(0xc420165900, 0x42f1a60, 0xc42013df20, 0xa, 0xc4201c4538)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:349 +0x2bb7 fp=0xc4201d8ac8 sp=0xc4201d7e58 pc=0x62983c7
github.com/santhosh-tekuri/jsonschema.(*Schema).validate(0xc420152280, 0x42f1a60, 0xc42013def0, 0x5ff, 0xc4201c4480)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:304 +0x30e4 fp=0xc4201d9738 sp=0xc4201d8ac8 pc=0x62988f4
github.com/santhosh-tekuri/jsonschema.(*Draft).validateSchema(0x44fb980, 0x635bc77, 0x1f, 0x0, 0x0, 0x42f1a60, 0xc42013def0, 0x4312d80, 0xc42013df01)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/compiler.go:43 +0x82 fp=0xc4201d97e8 sp=0xc4201d9738 pc=0x628c972
github.com/santhosh-tekuri/jsonschema.Compiler.compileRef(0x0, 0xc42013dec0, 0x635bc00, 0x44fb980, 0xc4201c8000, 0x0, 0x635bc77, 0x1f, 0x6353711, 0x1, ...)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/compiler.go:161 +0xd45 fp=0xc4201d99f8 sp=0xc4201d97e8 pc=0x628e3d5
github.com/santhosh-tekuri/jsonschema.(*Compiler).Compile(0xc420177ad0, 0x635bc77, 0x1f, 0x0, 0x0, 0x0)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/compiler.go:148 +0x164 fp=0xc4201d9aa0 sp=0xc4201d99f8 pc=0x628d4f4
github.com/santhosh-tekuri/jsonschema.Compile(0x635bc77, 0x1f, 0x20, 0x18, 0x6309b80)
/Users/msalvatore/git/GO/src/github.com/santhosh-tekuri/jsonschema/schema.go:95 +0x5b fp=0xc4201d9af8 sp=0xc4201d9aa0 pc=0x629536b
alert-middleware/common.LoadAndValidateJSONConfig(0x635bc77, 0x1f, 0xc42001b400, 0x1c, 0x6300200, 0xc4200fcde0, 0x0, 0x0)
/Users/msalvatore/git/GO/src/alert-middleware/common/util.go:27 +0x58 fp=0xc4201d9ba0 sp=0xc4201d9af8 pc=0x629c258
plugin/unnamed-959b4d77ea0d07e48cd2d1af7f5ffe965e53a6c8.(*Tag).LoadConfig(0xc4200fcde0, 0xc42001b400, 0x1c, 0xc4200fcde0, 0xc4201c43e8)
/Users/msalvatore/git/GO/src/alert-middleware/actions/tag.go:19 +0x64 fp=0xc4201d9bf0 sp=0xc4201d9ba0 pc=0x629c844
alert-middleware/common.(*PluginLoader).LoadActionPlugin(0xc420177dd0, 0xc420019920, 0x3, 0xc42001b400, 0x1c, 0x13, 0x0, 0x0, 0x428e9ae)
/Users/msalvatore/git/GO/src/alert-middleware/common/plugin_loader.go:38 +0x284 fp=0xc4201d9d40 sp=0xc4201d9bf0 pc=0x42960d4
main.main()
/Users/msalvatore/git/GO/src/alert-middleware/main.go:48 +0x3c3 fp=0xc4201d9f88 sp=0xc4201d9d40 pc=0x4296fd3
runtime.main()
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/proc.go:198 +0x212 fp=0xc4201d9fe0 sp=0xc4201d9f88 pc=0x402e4e2
runtime.goexit()
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc4201d9fe8 sp=0xc4201d9fe0 pc=0x40577d1

goroutine 2 [force gc (idle)]:
runtime.gopark(0x4361eb0, 0x4504d10, 0x434c79b, 0xf, 0x4361d14, 0x1)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/proc.go:291 +0x11a fp=0xc420044768 sp=0xc420044748 pc=0x402e93a
runtime.goparkunlock(0x4504d10, 0x434c79b, 0xf, 0x14, 0x1)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/proc.go:297 +0x5e fp=0xc4200447a8 sp=0xc420044768 pc=0x402e9ee
runtime.forcegchelper()
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/proc.go:248 +0xcc fp=0xc4200447e0 sp=0xc4200447a8 pc=0x402e77c
runtime.goexit()
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc4200447e8 sp=0xc4200447e0 pc=0x40577d1
created by runtime.init.4
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/proc.go:237 +0x35

goroutine 3 [GC sweep wait]:
runtime.gopark(0x4361eb0, 0x4504e00, 0x434be40, 0xd, 0x4020a14, 0x1)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/proc.go:291 +0x11a fp=0xc420044f60 sp=0xc420044f40 pc=0x402e93a
runtime.goparkunlock(0x4504e00, 0x434be40, 0xd, 0x14, 0x1)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/proc.go:297 +0x5e fp=0xc420044fa0 sp=0xc420044f60 pc=0x402e9ee
runtime.bgsweep(0xc420070000)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/mgcsweep.go:52 +0xa3 fp=0xc420044fd8 sp=0xc420044fa0 pc=0x4020a53
runtime.goexit()
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc420044fe0 sp=0xc420044fd8 pc=0x40577d1
created by runtime.gcenable
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/mgc.go:216 +0x58

goroutine 4 [finalizer wait]:
runtime.gopark(0x4361eb0, 0x45229a0, 0x434c3db, 0xe, 0x14, 0x1)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/proc.go:291 +0x11a fp=0xc420045718 sp=0xc4200456f8 pc=0x402e93a
runtime.goparkunlock(0x45229a0, 0x434c3db, 0xe, 0x14, 0x1)
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/proc.go:297 +0x5e fp=0xc420045758 sp=0xc420045718 pc=0x402e9ee
runtime.runfinq()
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/mfinal.go:175 +0xad fp=0xc4200457e0 sp=0xc420045758 pc=0x4017afd
runtime.goexit()
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc4200457e8 sp=0xc4200457e0 pc=0x40577d1
created by runtime.createfing
/usr/local/Cellar/go/1.10.1/libexec/src/runtime/mfinal.go:156 +0x62

@mssalvatore

I am able to compile your schema without any errors.
but you have not given me the json file to validate.
please give me the json file, to reproduce the issue...

from trace looks like, it is failing in compilation

but when i tried, i could not reproduce it. could you update jsonschema project and try it.

I'm using the latest commit.

I ran the code on my linux box using version 1.10.2 and it runs without issue. I upgraded my mac to 1.10.2 and I still see the issue. I guess this is a bug in the go compiler for OSX?

i am using OSX 10.13.1 go version go1.10.2 darwin/amd64
it works without issue...

Hmm. I'm on OSX 10.13.4. I don't know if that would make the difference.

I guess you can close this issue since It doesn't appear on your system or my linux system.

NOT_REPRODUCIBLE

I upgraded to OSX 10.13.4. but it works without issue...