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

Stack Overflow when parsing recursive types #86

Open
deanroker123 opened this issue May 21, 2019 · 6 comments
Open

Stack Overflow when parsing recursive types #86

deanroker123 opened this issue May 21, 2019 · 6 comments
Labels

Comments

@deanroker123
Copy link

Hi, I am trying to use xsdgen with a large xsd file with several large dependencies.

I get this error after a few seconds.

runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x7a70d4, 0xe)
/usr/local/go/src/runtime/panic.go:608 +0x72
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1008 +0x729
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:429 +0x8f

goroutine 1 [running]:
aqwari.net/xml/xsd.or.func1(0xc000234200, 0x0)
/home/droker/Development/go/src/aqwari.net/xml/xsd/search.go:20 +0x92 fp=0xc02191a368 sp=0xc02191a360 pc=0x597de2
aqwari.net/xml/xsd.hasChild.func1(0xc0004c7300, 0x597db5)
/home/droker/Development/go/src/aqwari.net/xml/xsd/search.go:33 +0x85 fp=0xc02191a3a0 sp=0xc02191a368 pc=0x597e75
aqwari.net/xml/xmltree.(*Element).SearchFunc.func1(0xc0004c7300)
/home/droker/Development/go/src/aqwari.net/xml/xmltree/xmltree.go:327 +0x45 fp=0xc02191a400 sp=0xc02191a3a0 pc=0x565ad5
aqwari.net/xml/xmltree.(*Element).walk(0xc000234100, 0xc0419190e0, 0xc000234100, 0x0)
/home/droker/Development/go/src/aqwari.net/xml/xmltree/xmltree.go:287 +0x3b fp=0xc02191a420 sp=0xc02191a400 pc=0x56520b
aqwari.net/xml/xmltree.(*Element).SearchFunc.func1(0xc000234100)
/home/droker/Development/go/src/aqwari.net/xml/xmltree/xmltree.go:330 +0xa0 fp=0xc02191a480 sp=0xc02191a420 pc=0x565b30
aqwari.net/xml/xmltree.(*Element).walk(0xc000563800, 0xc0419190e0, 0xc000563800, 0x0)
/home/droker/Development/go/src/aqwari.net/xml/xmltree/xmltree.go:287 +0x3b fp=0xc02191a4a0 sp=0xc02191a480 pc=0x56520b
aqwari.net/xml/xmltree.(*Element).SearchFunc.func1(0xc000563800)..............

There is a huge stack trace.

Any ideas if there is anything I can do?

Thanks

Dean

@deanroker123
Copy link
Author

Sorry thought I was on the wrong github repo. I still have this issue.

@droyo
Copy link
Owner

droyo commented May 22, 2019

Thanks for the report.

It's possible that a loop was created in the tree during parsing by one of the passes in the xsd package.

If you are able to share the xsd file I can take a look. If you're not, you could start by running the xsdparse utility against the document. xsdparse will just parse the file and apply some normalization steps. That will rule out any transformations that the xsdgen package performs.

@deanroker123
Copy link
Author

deanroker123 commented May 22, 2019

I get the same problem with xsdparse.

Here is the file in question. I added some logging in question and I think its to do with the global attributes file. It is pretty big.

Attachment removed

Let me know when you have the file and I will remove the link.

@droyo
Copy link
Owner

droyo commented May 23, 2019

Thanks, I have it and reproduced your issue.

I am still in the process of debugging. The problem appears to be in the xsd.flattenRef transformation. It is creating a loop in the document tree. This appears to be a recently introduced bug, since I was able to parse the documents with an older version of xsdparse

@droyo
Copy link
Owner

droyo commented May 23, 2019

I think I see the issue. There is an element in mod_base.xsd refers to itself:

<xs:element name="sup">
  <xs:complexType mixed="true">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      ...
      <xs:element ref="sup"/>

XML schema does allow recursive types[1], I've just never accounted for them. For xsdgen, we could use pointers to model a recursive type:

type Sup struct {
    ...
    Sup *Sup
    ...
}

@droyo droyo changed the title Stack Overflow when using xdsgen Stack Overflow when parsing recursive types May 23, 2019
@droyo droyo added the bug label May 23, 2019
@deanroker123
Copy link
Author

That sounds like a great idea. Thank you for the prompt investigation

droyo added a commit that referenced this issue May 27, 2019
boekkooi-fresh added a commit to boekkooi-fresh/go-xml that referenced this issue Jun 12, 2019
This should resolve issue droyo#86
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