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

Fix stack overflow when partially-__init__ Node raises exception. #7481

Merged
merged 3 commits into from Feb 23, 2021

Conversation

areusch
Copy link
Contributor

@areusch areusch commented Feb 19, 2021

  • If a Node subclass raises an exception and ctypes is in use before
    init_handle_by_constructor is called (or self.handle is
    otherwise set), a Python stack overflow could result. This is
    because the unset handle slot causes self.handle accesses to
    fallback on the getattr(self, 'handle') method, invoking
    NodeGetAttr.
  • Then I believe this causes an infinite loop.
  • The fix is to make Node.getattr raise AttributeError for all
    attributes in slots, then make del tolerant to missing
    self.handle.
  • I don't believe cython is affected because it implements a
    descriptor to access its underlying chandle and that shouldn't be unset.

 * If a Node subclass raises an exception and ctypes is in use before
   __init_handle_by_constructor__ is called (or self.handle is
   otherwise set), a Python stack overflow could result. This is
   because the unset handle slot causes self.handle accesses to
   fallback on the getattr(self, 'handle') method, invoking
   NodeGetAttr.
 * Then I believe this causes an infinite loop.
 * The fix is to make Node.__getattr__ raise AttributeError for all
   attributes in __slots__, then make __del__ tolerant to missing
   self.handle.
 * I don't believe cython is affected because it implements a
   descriptor to access its underlying chandle and that shouldn't be unset.
@areusch
Copy link
Contributor Author

areusch commented Feb 19, 2021

@tqchen tqchen merged commit 929717a into apache:main Feb 23, 2021
Lokiiiiii pushed a commit to Lokiiiiii/tvm that referenced this pull request Mar 2, 2021
…ache#7481)

* Fix stack overflow when partially-__init__ Node raises exception.

 * If a Node subclass raises an exception and ctypes is in use before
   __init_handle_by_constructor__ is called (or self.handle is
   otherwise set), a Python stack overflow could result. This is
   because the unset handle slot causes self.handle accesses to
   fallback on the getattr(self, 'handle') method, invoking
   NodeGetAttr.
 * Then I believe this causes an infinite loop.
 * The fix is to make Node.__getattr__ raise AttributeError for all
   attributes in __slots__, then make __del__ tolerant to missing
   self.handle.
 * I don't believe cython is affected because it implements a
   descriptor to access its underlying chandle and that shouldn't be unset.

* black format

* actually use handle instead of self.handle
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Mar 2, 2021
…ache#7481)

* Fix stack overflow when partially-__init__ Node raises exception.

 * If a Node subclass raises an exception and ctypes is in use before
   __init_handle_by_constructor__ is called (or self.handle is
   otherwise set), a Python stack overflow could result. This is
   because the unset handle slot causes self.handle accesses to
   fallback on the getattr(self, 'handle') method, invoking
   NodeGetAttr.
 * Then I believe this causes an infinite loop.
 * The fix is to make Node.__getattr__ raise AttributeError for all
   attributes in __slots__, then make __del__ tolerant to missing
   self.handle.
 * I don't believe cython is affected because it implements a
   descriptor to access its underlying chandle and that shouldn't be unset.

* black format

* actually use handle instead of self.handle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants