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

Incorrect range checks/documentation in curses #86847

Closed
arbor mannequin opened this issue Dec 19, 2020 · 14 comments
Closed

Incorrect range checks/documentation in curses #86847

arbor mannequin opened this issue Dec 19, 2020 · 14 comments
Assignees
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir stdlib Python modules in the Lib dir

Comments

@arbor
Copy link
Mannequin

arbor mannequin commented Dec 19, 2020

BPO 42681
Nosy @vstinner, @serhiy-storchaka, @ZackerySpytz, @pablogsal
PRs
  • bpo-42681: Fix range checks for color and pair numbers in curses #23874
  • [3.9] bpo-42681: Fix range checks for color and pair numbers in curses (GH-23874). #24077
  • [3.8] [3.9] bpo-42681: Fix range checks for color and pair numbers in curses (GH-23874). (GH-24077) #24079
  • bpo-42681: Fix test_curses failures related to COLOR_PAIRS #24089
  • [3.9] bpo-42681: Fix test_curses failures related to color pairs (GH-24089) #24113
  • [3.8] [3.9] bpo-42681: Fix test_curses failures related to color pairs (GH-24089) (GH-24113) #24116
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2021-01-05.14:33:37.311>
    created_at = <Date 2020-12-19.00:58:57.465>
    labels = ['3.8', 'library', '3.9', '3.10', 'docs']
    title = 'Incorrect range checks/documentation in curses'
    updated_at = <Date 2021-01-06.11:32:07.760>
    user = 'https://bugs.python.org/arbor'

    bugs.python.org fields:

    activity = <Date 2021-01-06.11:32:07.760>
    actor = 'vstinner'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2021-01-05.14:33:37.311>
    closer = 'serhiy.storchaka'
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2020-12-19.00:58:57.465>
    creator = 'arbor'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42681
    keywords = ['patch']
    message_count = 14.0
    messages = ['383344', '383385', '383403', '384296', '384301', '384302', '384304', '384309', '384371', '384388', '384398', '384402', '384403', '384492']
    nosy_count = 6.0
    nosy_names = ['vstinner', 'docs@python', 'serhiy.storchaka', 'ZackerySpytz', 'pablogsal', 'arbor']
    pr_nums = ['23874', '24077', '24079', '24089', '24113', '24116']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue42681'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @arbor
    Copy link
    Mannequin Author

    arbor mannequin commented Dec 19, 2020

    The description of color_pair starts with

    curses.color_pair(color_number)

    It should be

    curses.color_pair(pair_number)

    @arbor arbor mannequin assigned docspython Dec 19, 2020
    @arbor arbor mannequin added 3.10 only security fixes docs Documentation in the Doc dir labels Dec 19, 2020
    @arbor arbor mannequin assigned docspython Dec 19, 2020
    @arbor arbor mannequin added 3.10 only security fixes docs Documentation in the Doc dir labels Dec 19, 2020
    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented Dec 19, 2020

    Please explain why you believe this is a mistake.

    @serhiy-storchaka
    Copy link
    Member

    Good catch! And it is not only documentation issue now. Since color numbers and pair numbers use different range checks, this prevents using this function with pair numbers larger that COLORS (should be accepted up to COLOR_PAIRS-1).

    Seems there is also other bug which prevents using pair number 0 (constant white on black).

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir 3.8 only security fixes 3.9 only security fixes labels Dec 19, 2020
    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir 3.8 only security fixes 3.9 only security fixes labels Dec 19, 2020
    @serhiy-storchaka
    Copy link
    Member

    New changeset 1470edd by Serhiy Storchaka in branch 'master':
    bpo-42681: Fix range checks for color and pair numbers in curses (GH-23874)
    1470edd

    @serhiy-storchaka serhiy-storchaka changed the title mistake in curses documentation Incorrect range checks/documentation in curses Jan 3, 2021
    @serhiy-storchaka serhiy-storchaka changed the title mistake in curses documentation Incorrect range checks/documentation in curses Jan 3, 2021
    @serhiy-storchaka
    Copy link
    Member

    New changeset b0ee2b4 by Serhiy Storchaka in branch '3.9':
    [3.9] bpo-42681: Fix range checks for color and pair numbers in curses (GH-23874). (GH-24077)
    b0ee2b4

    @pablogsal
    Copy link
    Member

    This change seems to broke some buildbots. For instance:

    https://buildbot.python.org/all/#/builders/119/builds/153

    ======================================================================
    ERROR: test_colors_funcs (test.test_curses.TestCurses)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/home/dje/cpython-buildarea/3.8.edelsohn-rhel8-z/build/Lib/test/test_curses.py", line 310, in test_colors_funcs
        curses.pair_content(min(curses.COLOR_PAIRS - 1, 0x7fff))
    _curses.error: Argument 1 was out of range. (1..COLOR_PAIRS-1)

    Ran 28 tests in 0.337s
    FAILED (errors=1)
    1 test failed again:
    test_curses
    == Tests result: FAILURE then FAILURE ==

    @vstinner
    Copy link
    Member

    vstinner commented Jan 3, 2021

    This change seems to broke some buildbots.

    Yep, see also bpo-42789.

    @serhiy-storchaka
    Copy link
    Member

    New changeset 82794ca by Serhiy Storchaka in branch '3.8':
    [3.8] [3.9] bpo-42681: Fix range checks for color and pair numbers in curses (GH-23874). (GH-24077) (GH-24079)
    82794ca

    @serhiy-storchaka
    Copy link
    Member

    New changeset 59f9b4e by Serhiy Storchaka in branch 'master':
    bpo-42681: Fix test_curses failures related to color pairs (GH-24089)
    59f9b4e

    @serhiy-storchaka
    Copy link
    Member

    New changeset 9b3a53a by Serhiy Storchaka in branch '3.9':
    [3.9] bpo-42681: Fix test_curses failures related to color pairs (GH-24089) (GH-24113)
    9b3a53a

    @serhiy-storchaka
    Copy link
    Member

    New changeset e2c847e by Serhiy Storchaka in branch '3.8':
    [3.8] [3.9] bpo-42681: Fix test_curses failures related to color pairs (GH-24089) (GH-24113) (GH-24116)
    e2c847e

    @serhiy-storchaka
    Copy link
    Member

    Well, a simple documentation issue has grown into large and complex changes that fix several bugs.

    • Incorrect parameter name in color_pair().
    • Incorrectly documented ranges for color and pair numbers.
    • Based on incorrect documentation, incorrect checks was implemented in the code.
    • It was not caught earlier because most tests were skipped on buildbots.
    • BTW ncurses accepts some values outside of the documented ranges.
    • But ncurses 6.1 does not accept all values in the documented ranges.
    • There were other minor bugs introduced in bpo-36982.

    @pablogsal
    Copy link
    Member

    Thanks a lot Serhiy for the fantastic work!

    @vstinner
    Copy link
    Member

    vstinner commented Jan 6, 2021

    Great work, thank you Serhiy!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants