[New-bugs-announce] [issue26595] Segfault on Pointer operation

Emin Ghuliev report at bugs.python.org
Sun Mar 20 10:14:22 EDT 2016

New submission from Emin Ghuliev:

I'm trying use a pointer on python script but when executing the following code getting error. (Segmentation fault)

dmr at debian:~$ python test.py
Segmentation fault

self.mem  = c_char_p(mem)

pointer(self.binning())[0] = 0x41414141

EAX: 0x0 
EBX: 0xb7aee000 --> 0x21e4c 
ECX: 0x1 
EDX: 0x41414141 ('AAAA')
ESI: 0x41414141 ('AAAA')
EDI: 0x41414141 ('AAAA')
EBP: 0xb7b0eb3c --> 0xc ('\x0c')
ESP: 0xbfffeb74 --> 0x0 
EIP: 0xb7dfc4b6 (<__strlen_sse2_bsf+22>:	movdqu xmm1,XMMWORD PTR [edi])
EFLAGS: 0x10287 (CARRY PARITY adjust zero SIGN trap INTERRUPT direction overflow)
   0xb7dfc4ad <__strlen_sse2_bsf+13>:	pxor   xmm0,xmm0
   0xb7dfc4b1 <__strlen_sse2_bsf+17>:	cmp    ecx,0x30
   0xb7dfc4b4 <__strlen_sse2_bsf+20>:	ja     0xb7dfc4cd <__strlen_sse2_bsf+45>
=> 0xb7dfc4b6 <__strlen_sse2_bsf+22>:	movdqu xmm1,XMMWORD PTR [edi]
   0xb7dfc4ba <__strlen_sse2_bsf+26>:	pcmpeqb xmm0,xmm1
   0xb7dfc4be <__strlen_sse2_bsf+30>:	pmovmskb edx,xmm0
   0xb7dfc4c2 <__strlen_sse2_bsf+34>:	test   edx,edx
   0xb7dfc4c4 <__strlen_sse2_bsf+36>:	jne    0xb7dfc539 <__strlen_sse2_bsf+153>

BUG on ctypes module 


static PyObject *
z_get(void *ptr, unsigned size)
        /* XXX What about invalid pointers ??? */
        if (*(void **)ptr) {
#if defined(MS_WIN32) && !defined(_WIN32_WCE)
                if (IsBadStringPtrA(*(char **)ptr, -1)) {
                                     "invalid string pointer %p",
                                     *(char **)ptr);
                        return NULL;
                return PyString_FromString(*(char **)ptr); < === passing pointer as argument
        } else {
                return Py_None;
PyObject *
PyString_FromString(const char *str = this value assigned to 0x41414141 address)
	register size_t size;
	register PyStringObject *op;

	assert(str != NULL);
	size = strlen(str); <==== argument address 0x41414141

files: alloc.py
messages: 262077
nosy: Emin Ghuliev
priority: normal
severity: normal
status: open
title: Segfault on Pointer operation
Added file: http://bugs.python.org/file42224/alloc.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list