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

Structure field size/ofs __str__ wrong with large size fields #70045

Open
CharlesMachalow mannequin opened this issue Dec 14, 2015 · 2 comments
Open

Structure field size/ofs __str__ wrong with large size fields #70045

CharlesMachalow mannequin opened this issue Dec 14, 2015 · 2 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes topic-ctypes type-bug An unexpected behavior, bug, or error

Comments

@CharlesMachalow
Copy link
Mannequin

CharlesMachalow mannequin commented Dec 14, 2015

BPO 25858
Files
  • ctypesBug.py
  • 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 2015-12-14.02:52:09.933>
    labels = ['ctypes', 'type-bug', '3.8', '3.9', '3.10']
    title = 'Structure field size/ofs __str__ wrong with large size fields'
    updated_at = <Date 2020-11-08.18:15:58.491>
    user = 'https://bugs.python.org/CharlesMachalow'

    bugs.python.org fields:

    activity = <Date 2020-11-08.18:15:58.491>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['ctypes']
    creation = <Date 2015-12-14.02:52:09.933>
    creator = 'Charles Machalow'
    dependencies = []
    files = ['41299']
    hgrepos = []
    issue_num = 25858
    keywords = []
    message_count = 2.0
    messages = ['256359', '256361']
    nosy_count = 1.0
    nosy_names = ['Charles Machalow']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue25858'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @CharlesMachalow
    Copy link
    Mannequin Author

    CharlesMachalow mannequin commented Dec 14, 2015

    Large sized fields in Structures lead to incorrect string representations because it is assuming that because the size is so large, it must be a bit field instead of a byte field.

    class bugStruct(Structure):
        _pack_ = 1
        _fields_ = [
                    ("correct", c_uint8 * 65535),
                    ("wrongSizeAndOffset", c_uint8 * 999999),
                   ]
    
    print(str(bugStruct.correct))
    <Field type=c_ubyte_Array_65535, ofs=0, size=65535> # Correct
    
    print(str(bugStruct.wrongSizeAndOffset))
    <Field type=c_ubyte_Array_999999, ofs=65535:16959, bits=15> # Incorrect
    # Should be: <Field type=c_ubyte_Array_999999, ofs=65535, size=999999>

    To get the math for this do the following on an incorrect size/offset:
    size = (bits << 16) + ofs.split(":")[1]
    ofs = ofs.split(":")[0]
    Though this isn't really safe because the field may actually be bit-sized

    @CharlesMachalow CharlesMachalow mannequin added topic-ctypes type-bug An unexpected behavior, bug, or error labels Dec 14, 2015
    @CharlesMachalow
    Copy link
    Mannequin Author

    CharlesMachalow mannequin commented Dec 14, 2015

    Adding file with code to reproduce.

    @iritkatriel iritkatriel added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Nov 8, 2020
    @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 topic-ctypes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant