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

_winreg.EnumValue causes MemoryError #54146

Closed
kzmi mannequin opened this issue Sep 24, 2010 · 14 comments
Closed

_winreg.EnumValue causes MemoryError #54146

kzmi mannequin opened this issue Sep 24, 2010 · 14 comments
Labels
OS-windows type-bug An unexpected behavior, bug, or error

Comments

@kzmi
Copy link
Mannequin

kzmi mannequin commented Sep 24, 2010

BPO 9937
Nosy @vstinner, @tjguk, @eryksun, @iritkatriel
Files
  • fonts.reg: Sample registory data
  • test.py: py file to reproduce
  • 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 = <Date 2022-01-07.10:06:55.079>
    created_at = <Date 2010-09-24.09:17:15.592>
    labels = ['type-bug', 'OS-windows']
    title = '_winreg.EnumValue causes MemoryError'
    updated_at = <Date 2022-01-07.10:06:55.076>
    user = 'https://bugs.python.org/kzmi'

    bugs.python.org fields:

    activity = <Date 2022-01-07.10:06:55.076>
    actor = 'eryksun'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-07.10:06:55.079>
    closer = 'eryksun'
    components = ['Windows']
    creation = <Date 2010-09-24.09:17:15.592>
    creator = 'kzmi'
    dependencies = []
    files = ['18993', '18994']
    hgrepos = []
    issue_num = 9937
    keywords = ['patch']
    message_count = 14.0
    messages = ['117264', '117265', '117266', '117289', '117291', '117308', '117310', '117403', '117404', '117438', '117439', '222618', '409943', '409956']
    nosy_count = 6.0
    nosy_names = ['vstinner', 'ocean-city', 'tim.golden', 'kzmi', 'eryksun', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue9937'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @kzmi
    Copy link
    Mannequin Author

    kzmi mannequin commented Sep 24, 2010

    _winreg.EnumValue causes MemoryError if the name of the value contains multibyte unicode characters.

    I'm using 2.6.6.
    I think it is relevant to Isssue bpo-2810.

    @kzmi kzmi mannequin added OS-windows type-bug An unexpected behavior, bug, or error labels Sep 24, 2010
    @kzmi
    Copy link
    Mannequin Author

    kzmi mannequin commented Sep 24, 2010

    Added sample registory data file.

    @kzmi
    Copy link
    Mannequin Author

    kzmi mannequin commented Sep 24, 2010

    Added py file to reproduce.

    @briancurtin
    Copy link
    Member

    I'm not able to reproduce any MemoryError on 2.6, 2.7, or 3.2 on Windows 7 using your registry data and test script.

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Sep 24, 2010

    I can reproduce the issue on python2.x. I cannot on
    python3.x.

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Sep 24, 2010

    This happens because RegQueryInfoKeyA returns maximum value
    name length not in *Ansi* characters but in *Unicode" characters.
    I don't know clue why.

    http://msdn.microsoft.com/en-us/library/ms724902%28VS.85%29.aspx

    In multibyte environment, 2 or 3 bytes characters are
    mapped to one size unicode. So usually, the length of *Ansi*
    characters are larger than or equals to the length of *Unicode*
    characters. If every Ansi characters are mapped to one size
    Unicode, lengthes are equal, so probably this issue won't happen.

    I'll attach the patch to fix this issue. But be care, this is not
    tested so densely. At least, the script to reproduce this issue
    ran fine.

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Sep 24, 2010

    Again, I'm not sure this is right fix.

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Sep 26, 2010

    Sorry, my patch didn't pass test_dynamic_key(test_winreg).
    (Apologize for not testing on unit test)

    RegEnumValueA and RegQueryInfoKeyA always returned 0 for
    required data size if target is HKEY_PERFORMANCE_DATA.

    The possible fixes I can imagine are...

    1. Use GetCPInfo() to get MaxCharSize.
      http://msdn.microsoft.com/en-us/library/dd317780%28v=VS.85%29.aspx
      We can get a large value enough to store the key name in ANSI by
      "The length in Unicode" * MaxCharSize.

    2. Use RegEnumValueW and convert result via WideCharToMultiByte

    I'll attach the patch with option 1.

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Sep 26, 2010

    I shall create unit test later.

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Sep 27, 2010

    I've withdrew my patch... It has still problem, and
    I cannot fix it yet. I suppose option 2 is easy.
    ANSI API's limitation makes it harder to implement
    correctly.

    @vstinner
    Copy link
    Member

    Can't we use RegEnumValueW and RegQueryInfoKeyW?

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 9, 2014

    Does anyone wish to follow this up as I no longer run 2.7?

    @iritkatriel
    Copy link
    Member

    I can reproduce the issue on python2.x. I cannot on python3.x.

    Did anyone reproduce on python3.X? Why are versions 3.4/3.5 selected?

    @eryksun
    Copy link
    Contributor

    eryksun commented Jan 7, 2022

    Did anyone reproduce on python3.X?

    In principle, winreg should not have a problem in 3.x because it only uses the UTF-16 wide-character API.

    @eryksun eryksun closed this as completed Jan 7, 2022
    @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
    OS-windows type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants