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

IDLE: protect macOS Tk() call when no GUI #97527

Closed
terryjreedy opened this issue Sep 24, 2022 · 4 comments
Closed

IDLE: protect macOS Tk() call when no GUI #97527

terryjreedy opened this issue Sep 24, 2022 · 4 comments
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

terryjreedy commented Sep 24, 2022

The no-gui (mock Text) test_squeezer.SqueezerTest.test_write_stdout indirectly calls squeezer.Squeezer.mywrite, which calls macosx.isAquaTk, which calls _init_tk_type, which calls tkinter.Tk to initialize macosx._tk_type. When a test is run on macOS with no GUI, this crashes; see #97032 for an example.

test_squeezer later calls isAquaTk directly. Even if we fix test_squeezer, there are about 10 other isAquaTk calls in idlelib that someday might be triggered by more complete tests. I will try patching _init_tk_type in branch tktype to skip Tk() when it would crash.

@terryjreedy terryjreedy added type-bug An unexpected behavior, bug, or error topic-IDLE 3.11 only security fixes 3.10 only security fixes 3.12 bugs and security fixes labels Sep 24, 2022
terryjreedy added a commit to terryjreedy/cpython that referenced this issue Sep 24, 2022
Only call tkinter.tk and its follow-up code in _init_tk_type
when requires('gui') does not raise.  This function can be
called as an unintended side-effect of calling other idlelib
code as part of tests on macOS without a GUI enabled.
terryjreedy added a commit that referenced this issue Sep 24, 2022
Only call tkinter.tk and its follow-up code in _init_tk_type when requires('gui')
does not raise.  This function can be called as an unintended side-effect of
calling other idlelib code as part of tests on macOS without a GUI enabled.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 24, 2022
…97530)

Only call tkinter.tk and its follow-up code in _init_tk_type when requires('gui')
does not raise.  This function can be called as an unintended side-effect of
calling other idlelib code as part of tests on macOS without a GUI enabled.
(cherry picked from commit 9704f8d)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 24, 2022
…97530)

Only call tkinter.tk and its follow-up code in _init_tk_type when requires('gui')
does not raise.  This function can be called as an unintended side-effect of
calling other idlelib code as part of tests on macOS without a GUI enabled.
(cherry picked from commit 9704f8d)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington added a commit that referenced this issue Sep 24, 2022
Only call tkinter.tk and its follow-up code in _init_tk_type when requires('gui')
does not raise.  This function can be called as an unintended side-effect of
calling other idlelib code as part of tests on macOS without a GUI enabled.
(cherry picked from commit 9704f8d)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington added a commit that referenced this issue Sep 24, 2022
Only call tkinter.tk and its follow-up code in _init_tk_type when requires('gui')
does not raise.  This function can be called as an unintended side-effect of
calling other idlelib code as part of tests on macOS without a GUI enabled.
(cherry picked from commit 9704f8d)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@terryjreedy terryjreedy reopened this Oct 15, 2022
@terryjreedy
Copy link
Member Author

The fix in #97530 for a testing-only bug, merged after 3.11.rc2, introduced a runtime-only bug of disable IDLE startup when test/* is not installed. This bug was released in 3.12.0a1, 3.10.8, and Microsoft Python 3.10.2288.0. It was reported on SO for the last: https://stackoverflow.com/questions/74070702/python-m-idlelib-idle-not-working-windows-10/74082858#74082858.

The immediate fix for anyone is to delete the import on line 7 and replace the try suite on line 23 with pass. Windows people who omitted the test suite can Modify and add it.

@pablogsal I hope you did not cherr-pick the buggy 'fix' into 3.11.0. If you did, I will have a better fix soon.

@zooba Does MS Python allow installing the test? Once the new fix is merged, could you let the MS Python person know?

@ned-deily As near as I could tell, one cannot install psf mac python without the tests. Correct? Do you know about homebrew? (And will we ever be rid of some of the mac graphics options?)

[Longer term, I want to consolidate macosx imports and if possible only do them on mac.]

@pablogsal
Copy link
Member

All cherry picks will be done hours before the release so we are safe. Just tell me what you want me to add and I will make sure is there the day of the final release .

terryjreedy added a commit to terryjreedy/cpython that referenced this issue Oct 16, 2022
python#97530 fixed IDLE tests possibly crashing on a Mac without a GUI.
But it resulted in IDLE not starting in 3.10.8, 3.12.0a1, and
Microsoft Python 3.10.2288.0 when test/* is not installed.
After this patch, test.* is only imported when testing on Mac.
@terryjreedy
Copy link
Member Author

#98313 follows on #97530. Reversion or #97530 or merging of #98313 would only be essential if #97530 had already been merged. The net effect of both is to prevent test_idle possibly crashing macOS with no GUI, now or with test revisions. AFAIK, CI and buildbots only run current repository versions, not release versions. So I don't think the release needs any change.

terryjreedy added a commit that referenced this issue Oct 16, 2022
#97530 fixed IDLE tests possibly crashing on a Mac without a GUI.
But it resulted in IDLE not starting in 3.10.8, 3.12.0a1, and
Microsoft Python 3.10.2288.0 when test/* is not installed.
After this patch, test.* is only imported when testing on Mac.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 16, 2022
pythonGH-97530 fixed IDLE tests possibly crashing on a Mac without a GUI.
But it resulted in IDLE not starting in 3.10.8, 3.12.0a1, and
Microsoft Python 3.10.2288.0 when test/* is not installed.
After this patch, test.* is only imported when testing on Mac.
(cherry picked from commit 35fa5d5)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 16, 2022
pythonGH-97530 fixed IDLE tests possibly crashing on a Mac without a GUI.
But it resulted in IDLE not starting in 3.10.8, 3.12.0a1, and
Microsoft Python 3.10.2288.0 when test/* is not installed.
After this patch, test.* is only imported when testing on Mac.
(cherry picked from commit 35fa5d5)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 16, 2022
pythonGH-97530 fixed IDLE tests possibly crashing on a Mac without a GUI.
But it resulted in IDLE not starting in 3.10.8, 3.12.0a1, and
Microsoft Python 3.10.2288.0 when test/* is not installed.
After this patch, test.* is only imported when testing on Mac.
(cherry picked from commit 35fa5d5)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington added a commit that referenced this issue Oct 16, 2022
GH-97530 fixed IDLE tests possibly crashing on a Mac without a GUI.
But it resulted in IDLE not starting in 3.10.8, 3.12.0a1, and
Microsoft Python 3.10.2288.0 when test/* is not installed.
After this patch, test.* is only imported when testing on Mac.
(cherry picked from commit 35fa5d5)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington added a commit that referenced this issue Oct 16, 2022
GH-97530 fixed IDLE tests possibly crashing on a Mac without a GUI.
But it resulted in IDLE not starting in 3.10.8, 3.12.0a1, and
Microsoft Python 3.10.2288.0 when test/* is not installed.
After this patch, test.* is only imported when testing on Mac.
(cherry picked from commit 35fa5d5)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@zooba
Copy link
Member

zooba commented Oct 17, 2022

@terryjreedy No, the Store package doesn't have any way to install the test suite. If we need those helpers, they should be copied elsewhere (either idlelib, tkinter or unittest probably - I'll let you make that call).

That said, if they're only needed for Mac, then handling the import error should also be fine.

carljm added a commit to carljm/cpython that referenced this issue Oct 17, 2022
* main: (31 commits)
  pythongh-95913: Move subinterpreter exper removal to 3.11 WhatsNew (pythonGH-98345)
  pythongh-95914: Add What's New item describing PEP 670 changes (python#98315)
  Remove unused arrange_output_buffer function from zlibmodule.c. (pythonGH-98358)
  pythongh-98174: Handle EPROTOTYPE under macOS in test_sendfile_fallback_close_peer_in_the_middle_of_receiving (python#98316)
  pythonGH-98327: Reduce scope of catch_warnings() in _make_subprocess_transport (python#98333)
  pythongh-93691: Compiler's code-gen passes location around instead of holding it on the global compiler state (pythonGH-98001)
  pythongh-97669: Create Tools/build/ directory (python#97963)
  pythongh-95534: Improve gzip reading speed by 10% (python#97664)
  pythongh-95913: Forward-port int/str security change to 3.11 What's New in main (python#98344)
  pythonGH-91415: Mention alphabetical sort ordering in the Sorting HOWTO (pythonGH-98336)
  pythongh-97930: Merge with importlib_resources 5.9 (pythonGH-97929)
  pythongh-85525: Remove extra row in doc (python#98337)
  pythongh-85299: Add note warning about entry point guard for asyncio example (python#93457)
  pythongh-97527: IDLE - fix buggy macosx patch (python#98313)
  pythongh-98307: Add docstring and documentation for SysLogHandler.createSocket (pythonGH-98319)
  pythongh-94808: Cover `PyFunction_GetCode`, `PyFunction_GetGlobals`, `PyFunction_GetModule` (python#98158)
  pythonGH-94597: Deprecate child watcher getters and setters (python#98215)
  pythongh-98254: Include stdlib module names in error messages for NameErrors (python#98255)
  Improve speed. Reduce auxiliary memory to 16.6% of the main array. (pythonGH-98294)
  [doc] Update logging cookbook with an example of custom handling of levels. (pythonGH-98290)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes topic-IDLE type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

3 participants