classification
Title: ctypes "ValueError: NULL pointer access" on Win7 x64
Type: crash Stage: resolved
Components: ctypes Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: theller Nosy List: ghazel, mattip, ocean-city, stan.mihai, theller
Priority: normal Keywords: patch

Created on 2010-07-15 12:55 by ghazel, last changed 2014-05-14 10:01 by berker.peksag. This issue is now closed.

Files
File name Uploaded Description Edit
ctypes_test.zip ghazel, 2010-07-16 04:29
ctypes_win64.diff stan.mihai, 2011-01-26 09:16 one-liner fix review
Messages (5)
msg110362 - (view) Author: Greg Hazel (ghazel) Date: 2010-07-15 12:55
ctypes on Windows on a 64bit Python installation gets a NULL pointer access where one is not expected.

To reproduce the problem, run make.bat then "python ctypes_test.py"


Failure output looks like this:

Three! 1 2 <__main__.LP_Some object at 0x000000000209C4C8>
<__main__.Some object at 0x000000000209C548>
91
Four! 1 2 3 <__main__.LP_Some object at 0x000000000209C4C8>
Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 291, in 'calling callback function'
  File "ctypes_test.py", line 21, in fourprinter
    print(to.contents)
ValueError: NULL pointer access


Otherwise, successful output looks something like:

Three! 1 2 <ctypes.LP_Some object at 0x2acc9482aed0>
<__main__.Some object at 0x2acc9482ae50>
91
Four! 1 2 3 <ctypes.LP_Some object at 0x2acc9482aed0>
<__main__.Some object at 0x2acc9482ae50>
91



Environments exhibiting this problem:

Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.architecture()
('64bit', 'WindowsPE')

Python 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.architecture()
('64bit', 'WindowsPE')


Environments NOT exhibiting the problem:

Python 2.4.3 (#1, Sep  3 2009, 15:37:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.architecture()
('64bit', 'ELF')

Also Windows on a 32bit architecture seems unaffected.
msg110412 - (view) Author: Greg Hazel (ghazel) Date: 2010-07-16 04:29
Ok, this issue is worse, and much easier to reproduce, than I thought. Here is an updated ctypes_test.zip with a repro using only integers and callbacks.

Correct output:
('three', (1, 2, 3))
('four', (1, 2, 3, 4))
('five', (1, 2, 3, 4, 5))

Incorrect output:
('three', (1, 2, 3))
('four', (1, 2, 3, 0))
('five', (1, 2, 3, 0, 5))

I built Python 2.7 from source with MSVC 9. This is not reproducible in Debug mode, or Win32 Release mode. It only happens in x64 Release mode. 

One very interesting discovery is that if I set these options:

Optimization: Disabled (/Od)
Enable Instrinsic Functions: No

the error does not occur!
msg117928 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2010-10-03 19:34
Probably this issue is duplicate of #9884.
msg127094 - (view) Author: stan mihai (stan.mihai) Date: 2011-01-26 09:16
The problem was an uninitialized variable. Attached is the patch that fixes it.
msg218496 - (view) Author: mattip (mattip) * Date: 2014-05-14 01:04
This was fixed with changeset 8fa73a0885c9 in Jan 2011, probably should be closed
History
Date User Action Args
2014-05-14 10:01:12berker.peksagsetstatus: open -> closed
resolution: out of date
stage: resolved
2014-05-14 01:04:28mattipsetnosy: + mattip
messages: + msg218496
2011-01-26 09:16:42stan.mihaisetfiles: + ctypes_win64.diff

nosy: + stan.mihai
messages: + msg127094

keywords: + patch
2010-10-03 19:34:44ocean-citysetnosy: + ocean-city
messages: + msg117928
2010-07-16 04:29:06ghazelsetfiles: + ctypes_test.zip

messages: + msg110412
2010-07-16 04:15:33ghazelsetfiles: - ctypes_test.zip
2010-07-15 12:55:48ghazelcreate