class SafeStream has a potentially unsafe __getattr__ implementation (potentially yielding an infinite recursion when attempting to pickle it)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 10
Description
| @thehcma reported | |
|---|---|
| Trac ID | trac#9612 |
| Type | defect |
| Created | 2019-04-05 17:14:47Z |
The problem happens when a SafeStream object gets pickled/unpickled.
This happens due to the implementation not safeguarding against the potential for infinite recursion when getattr would invoke its own __getattr__.
Here is an example of the recursion:
File "/home/blah/local/lib/python2.7/site-packages/twisted/trial/reporter.py", line 56, in __getattr__
return getattr(self.original, name)
File "/home/blah/lib/python2.7/site-packages/twisted/trial/reporter.py", line 56, in __getattr__
return getattr(self.original, name)
File "/home/blah/local/lib/python2.7/site-packages/twisted/trial/reporter.py", line 56, in __getattr__
Here is an exact description of the problem (and solution):
https://stackoverflow.com/questions/22781872/python-pickle-got-acycle-recursion-with-getattr
In fact, the first suggested solution works to prevent the potential for infinite recursion.
Here is the alternative implementation that addresses the problem:
def __getattr__(self, name):
original = object.__getattribute__(self, 'original')
return getattr(original, name)
Searchable metadata
trac-id__9612 9612
type__defect defect
reporter__thehcma thehcma
priority__normal normal
milestone__None None
branch__
branch_author__
status__new new
resolution__None None
component__core core
keywords__None None
time__1554484487597160 1554484487597160
changetime__1554493322402629 1554493322402629
version__None None
owner__None None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in twisted/trial/reporter.py at SafeStream.getattr, then reproduce the pickle/unpickle case described in the issue. Verify that accessing a missing attribute during unpickling no longer recurses indefinitely and add or update a focused regression test for that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100