GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-143008: fix TextIOWrapper.truncate via re-entrant flush by yihong0618 · Pull Request #143041 · python/cpython Conversation
|
| # instead of crashing. | ||
| wrapper = None | ||
|
|
||
| class BadRaw(self.RawIOBase): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
There's a number of mock helpers defined in test_io/utils.py to make it so can reduce this to just the methods that matter. I think self.MockRawIO will work here
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
thanks
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| with self.subTest(name): | ||
| wrapper = self.TextIOWrapper(EvilBuffer(BadRaw()), encoding='utf-8') | ||
| self.assertRaisesRegex(RuntimeError, "reentrant", method) | ||
| wrapper = None |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
can we make the gc / closing here more explicit? del wrapper?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
thanks
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| static inline int | ||
| _textiowrapper_flush(textio *self) | ||
| { | ||
| self->flushing = 1; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why can't this be in _io_TextIOWrapper_flush_impl?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
it can, the design is cover it in _PyFile_Flush
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
dropped
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| PyObject *ret; | ||
| self->flushing = 1; | ||
| do { | ||
| ret = PyObject_CallMethodOneArg(self->buffer, &_Py_ID(write), b); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
every loop iteration / write call could execute arbitrary interpreter code that could invalidate self->buffer so likely need to check on each loop iteration.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
will check, but I think maybe not need
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
dropped
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I think you are right but |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
And I can change it to my first solution or waiting for other discuss here? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…akErJ.rst Co-authored-by: Cody Maloney <[email protected]>
|
I agree Can you explain what your first solution is? I'm not understanding what you're referring to. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This will break the case when flush() was intentionally overridden.
I am not also sure that it fixes the core issue, it just makes a particular reproducer no longer working.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
will dig it, thank you |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
after some check and work I do not think |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Signed-off-by: yihong0618 <[email protected]>
There was an error while loading. Please reload this page.
I made some change but not sure its better idea, can you help to check? Thank you very much. if you have better way to fix all of them feel free to close it~ thanks again |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm starting to think a small refactor of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
will try to understand and learn it thank you |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
TextIOWrapper keeps its underlying stream in a member called `self->buffer`. That stream can be detached by user code, such as custom `.flush` implementations resulting in `self->buffer` being set to NULL. The implementation often checked at the start of functions if `self->buffer` is in a good state, but did not always recheck after other Python code was called which could modify `self->buffer`. The cases which need to be re-checked are hard to spot so rather than rely on reviewer effort create better safety by making all self->buffer access go through helper functions. Thank you yihong0618 for the test, NEWS and initial implementation in pythongh-143041. Co-authored-by: yihong0618 <[email protected]>
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…stream access (#145957) TextIOWrapper keeps its underlying stream in a member called `self->buffer`. That stream can be detached by user code, such as custom `.flush` implementations resulting in `self->buffer` being set to NULL. The implementation often checked at the start of functions if `self->buffer` is in a good state, but did not always recheck after other Python code was called which could modify `self->buffer`. The cases which need to be re-checked are hard to spot so rather than rely on reviewer effort create better safety by making all self->buffer access go through helper functions. Thank you yihong0618 for the test, NEWS and initial implementation in gh-143041. Co-authored-by: yihong0618 <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
|
#145957 was merged instead. Thanks for your contribution anyway! The merged change is based on your work and you're credited in the change ;-) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…lying stream access (python#145957) TextIOWrapper keeps its underlying stream in a member called `self->buffer`. That stream can be detached by user code, such as custom `.flush` implementations resulting in `self->buffer` being set to NULL. The implementation often checked at the start of functions if `self->buffer` is in a good state, but did not always recheck after other Python code was called which could modify `self->buffer`. The cases which need to be re-checked are hard to spot so rather than rely on reviewer effort create better safety by making all self->buffer access go through helper functions. Thank you yihong0618 for the test, NEWS and initial implementation in pythongh-143041. Co-authored-by: yihong0618 <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
…rant detach (#159591) * gh-143008: Fix Null pointer dereferences in TextIOWrapper underlying stream access (#145957) TextIOWrapper keeps its underlying stream in a member called `self->buffer`. That stream can be detached by user code, such as custom `.flush` implementations resulting in `self->buffer` being set to NULL. The implementation often checked at the start of functions if `self->buffer` is in a good state, but did not always recheck after other Python code was called which could modify `self->buffer`. The cases which need to be re-checked are hard to spot so rather than rely on reviewer effort create better safety by making all self->buffer access go through helper functions. Thank you yihong0618 for the test, NEWS and initial implementation in gh-143041. Co-authored-by: yihong0618 <[email protected]> Co-authored-by: Victor Stinner <[email protected]> (cherry picked from commit db4b194) * gh-154523: Fix data-race in `TextIOWrapper.detach()` (#154565) (cherry picked from commit 8440a6a) * gh-157364: Fix use-after-free in io.TextIOWrapper during reentrant detach (#157370) Co-authored-by: Victor Stinner <[email protected]> (cherry picked from commit e19dc47) --------- Co-authored-by: Cody Maloney <[email protected]> Co-authored-by: yihong0618 <[email protected]> Co-authored-by: Brij Kapadia <[email protected]> Co-authored-by: Shamil <[email protected]>
…rant detach (#159600) [3.15] gh-157364: Fix use-after-free in io.TextIOWrapper during reentrant detach (#159591) * gh-143008: Fix Null pointer dereferences in TextIOWrapper underlying stream access (#145957) TextIOWrapper keeps its underlying stream in a member called `self->buffer`. That stream can be detached by user code, such as custom `.flush` implementations resulting in `self->buffer` being set to NULL. The implementation often checked at the start of functions if `self->buffer` is in a good state, but did not always recheck after other Python code was called which could modify `self->buffer`. The cases which need to be re-checked are hard to spot so rather than rely on reviewer effort create better safety by making all self->buffer access go through helper functions. Thank you yihong0618 for the test, NEWS and initial implementation in gh-143041. (cherry picked from commit db4b194) * gh-154523: Fix data-race in `TextIOWrapper.detach()` (#154565) (cherry picked from commit 8440a6a) * gh-157364: Fix use-after-free in io.TextIOWrapper during reentrant detach (#157370) (cherry picked from commit e19dc47) --------- (cherry picked from commit ea1312b) Co-authored-by: Cody Maloney <[email protected]> Co-authored-by: yihong0618 <[email protected]> Co-authored-by: Brij Kapadia <[email protected]> Co-authored-by: Shamil <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.