Skip to content

wrong type for wintypes.BYTE #60580

Closed
Closed

Description

@techtonik
mannequin
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

    Activity

    1. techtonik commented on Oct 31, 2012

      techtonikmannequin
      MannequinAuthor

      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

    2. BreamoreBoy commented on Jul 13, 2014

      BreamoreBoymannequin
      Mannequin

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

    3. transferred this issue fromon Apr 10, 2022
    4. elibroftw commented on Sep 25, 2022

      @elibroftw

      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

    5. added
      3.12only security fixes
      and removed
      3.11only security fixes
      on Jan 26, 2023
    6. self-assigned this
      on Jan 26, 2023
    7. added a commit that references this issue on Jan 26, 2023
    8. added a commit that references this issue on Jan 31, 2023
    9. arhadthedev commented on Feb 4, 2023

      @arhadthedev
      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

    Metadata

    Metadata

    Assignees

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions