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

wrong type for wintypes.BYTE #60580

Closed
techtonik mannequin opened this issue Oct 31, 2012 · 4 comments
Closed

wrong type for wintypes.BYTE #60580

techtonik mannequin opened this issue Oct 31, 2012 · 4 comments
Assignees
Labels
3.12 bugs and security fixes OS-windows topic-ctypes type-bug An unexpected behavior, bug, or error

Comments

@techtonik
Copy link
Mannequin

techtonik mannequin commented Oct 31, 2012

BPO 16376
Nosy @amauryfa, @abalkin, @meadori
Files
  • Issue16376.diff: Change BYTE definition fron c_byte to c_ubyte
  • 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 = None
    closed_at = None
    created_at = <Date 2012-10-31.17:02:55.557>
    labels = ['ctypes', 'type-bug', '3.9', '3.10', '3.11']
    title = 'wrong type for wintypes.BYTE'
    updated_at = <Date 2021-06-17.10:29:15.374>
    user = 'https://bugs.python.org/techtonik'

    bugs.python.org fields:

    activity = <Date 2021-06-17.10:29:15.374>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['ctypes']
    creation = <Date 2012-10-31.17:02:55.557>
    creator = 'techtonik'
    dependencies = []
    files = ['35940']
    hgrepos = []
    issue_num = 16376
    keywords = ['patch']
    message_count = 2.0
    messages = ['174331', '222935']
    nosy_count = 4.0
    nosy_names = ['amaury.forgeotdarc', 'belopolsky', 'techtonik', 'meador.inge']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue16376'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Linked PRs

    @techtonik
    Copy link
    Mannequin Author

    techtonik mannequin commented Oct 31, 2012

    Windows BYTE type is unsigned char, but ctypes defines it as signed.

    {{{
    BYTE	
    A byte (8 bits).
    This type is declared in WinDef.h as follows:
    typedef unsigned char BYTE;
    typedef unsigned char BYTE;
    }}}
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx

    http://hg.python.org/cpython/file/e5f39546989f/Lib/ctypes/wintypes.py#l4

    @techtonik techtonik mannequin added the topic-ctypes label Oct 31, 2012
    @santosowijaya santosowijaya mannequin added the type-bug An unexpected behavior, bug, or error label Nov 1, 2012
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 13, 2014

    All cbytes tests passed after the change was made but I've no idea as to the impact of this.

    @iritkatriel iritkatriel added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Jun 17, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @elibroftw
    Copy link

    elibroftw commented Sep 25, 2022

    This bug can cause people to make grave mistakes when using WIndows APIs. Im assuming this is a simple fix too.
    Just because "cbytes" tests pass does not mean practical tests will pass. Take for example
    https://stackoverflow.com/a/6156606/7732434

    Run this code as shown and then run the code with types ctypes.c_ubyte instead of wintypes.BYTE. You can see that the latter works as expected according to Microsofts own specs as seen in the link below.

    https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-system_power_status

    This would be a wintypes.BYTE test that would not pass

    @abalkin abalkin added OS-windows 3.12 bugs and security fixes and removed 3.11 only security fixes 3.10 only security fixes 3.9 only security fixes labels Jan 26, 2023
    @abalkin abalkin self-assigned this Jan 26, 2023
    abalkin pushed a commit that referenced this issue Jan 26, 2023
    Created from a patch file attached to an issue, by Anatoly Techtonik.
    mdboom pushed a commit to mdboom/cpython that referenced this issue Jan 31, 2023
    )
    
    Created from a patch file attached to an issue, by Anatoly Techtonik.
    @arhadthedev
    Copy link
    Member

    Fixed by gh-97579; no backporting is planned.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.12 bugs and security fixes OS-windows topic-ctypes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants