Skip to content

Stack overflow when validating recursive structures #248

@cryptix

Description

@cryptix

Hi,

we are trying to validate conformance of some tree structure. Sadly we are seeing a stack overflow, even for simple cases like this:

;; example.cddl

; Root object
Tree = {
  root: Node
}

; Simple tree structure
Node = [
  value: text,
  children: [* Node]  ; Here's the recursion - Node contains Nodes
]

Here is some example data:

$ python
>>> import cbor2
>>> d = {
...   "root": ["value", [["child1", []], ["child2", []]]]
... }
>>> d
{'root': ['value', [['child1', []], ['child2', []]]]}
>>> cbor2.dumps(d).hex()
'a164726f6f74826576616c75658282666368696c64318082666368696c643280'

Running this through validate crashes the tool:

echo a164726f6f74826576616c75658282666368696c64318082666368696c643280 | xxd -r -p | cddl validate --stdin --cddl example.cddl
[INFO] Root type for validation: Tree

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted (core dumped)

Is this to be expected or am I just holding it wrong somehow?

Thanks

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions