This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: _winreg.QueryValue fault while reading mangled registry values
Type: behavior Stage: patch review
Components: Library (Lib), Windows Versions: Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ggenellina, ishimoto, steve.dower, tim.golden, toriningen, zach.ware
Priority: normal Keywords: needs review, patch

Created on 2008-12-22 15:06 by toriningen, last changed 2022-04-11 14:56 by admin.

Messages (7)
msg78190 - (view) Author: Alex (toriningen) Date: 2008-12-22 15:06
== What steps will reproduce the problem?
1. Create registry key (let's assume it's located in
2. Walk to it in "regedit";
3. Right-click on "(Default)" and select "Modify binary data";
4. Leave everything blank and press "OK";
5. Go to Python and execute this:
>>> import _winreg
>>> _winreg.QueryValue(_winreg.HKEY_CURRENT_USER, 'TestKey')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: ..\Objects\stringobject.c:4271: bad argument to internal

== What is the expected output? What do you see instead?
I expect either returning "''" or some ValueError indicating that source
string is malformed.

== What version of the product are you using? On what operating system?
1. Windows XP Professional SP2 English;
2. Tested on Python 2.5.2;
3. Tested on Python 2.6.1;
4. Tested on Stackless Python 2.5.2.

== Please provide any additional information below.
And yes, I know that this function is lame and everybody using it also
is lame, but it's not really a reason to include buggy functions, right?
msg94917 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2009-11-05 03:40
The attached patch will return "" in the case that Alex describes.
However, I haven't been able to reproduce his actions outside of
manually running the steps, so I don't have a test written for it.
Anyone know how to reproduce it from code?
msg95009 - (view) Author: Gabriel Genellina (ggenellina) Date: 2009-11-07 05:44
I cannot reproduce this bug with the current 2.6.4 release - it is 
either fixed or masked now.
msg95026 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2009-11-07 20:40
It happens to me on trunk with Windows XP. I also have access to Windows
Server 2003 where I can test this (haven't yet). Which version are you
running that you don't see this issue?
msg95246 - (view) Author: Gabriel Genellina (ggenellina) Date: 2009-11-14 17:28
I've noticed this depends on the user privileges. When logged in as a 
normal user, I get the internal error as originally reported. When 
logged in as an administrator, there is no error and I get an empty 
msg98094 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-21 02:00
On Windows 7, I see the issue as both a regular user and one with admin privileges. The patch (updated to fix tab/space difference) seems to do the trick. 
Gabriel, which OS are you on that this works differently based on the user privileges?

I'm still not sure how to test this...not sure how to modify the binary data and leave it blank via code.
msg224268 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-29 22:40
I can't reproduce this with 64 bit Windows 8.1 using 3.4.1 or 3.5.0a0, I don't have 2.7 to test on.
Date User Action Args
2022-04-11 14:56:43adminsetgithub: 48972
2019-04-26 20:11:56BreamoreBoysetnosy: - BreamoreBoy
2014-07-29 22:55:55brian.curtinsetnosy: - brian.curtin
2014-07-29 22:40:31BreamoreBoysetnosy: + BreamoreBoy, zach.ware, tim.golden, steve.dower

messages: + msg224268
versions: + Python 2.7, - Python 2.6
2012-07-30 15:21:35ishimotosetnosy: + ishimoto
2010-02-05 21:41:31brian.curtinsetfiles: - issue4722.diff
2010-01-21 02:00:22brian.curtinsetfiles: + issue4722.diff

messages: + msg98094
2010-01-21 01:51:42brian.curtinsetfiles: - issue4722_20091104_v1.patch
2010-01-13 02:08:03brian.curtinsetpriority: normal
keywords: + needs review
stage: patch review
versions: - Python 2.5
2009-11-14 17:28:26ggenellinasetmessages: + msg95246
2009-11-07 20:40:07brian.curtinsetmessages: + msg95026
2009-11-07 05:44:22ggenellinasetmessages: + msg95009
2009-11-05 03:40:25brian.curtinsetfiles: + issue4722_20091104_v1.patch

nosy: + brian.curtin
messages: + msg94917

keywords: + patch
2008-12-26 19:55:30ggenellinasetnosy: + ggenellina
2008-12-22 15:06:31toriningencreate