[New-bugs-announce] [issue17928] PowerLinux getargs.c FETCH_SIZE endianness bug

David Edelsohn report at bugs.python.org
Tue May 7 20:29:22 CEST 2013

New submission from David Edelsohn:

Another endianness bug that causes a failure in test_structmembers.py.

_testcapi reports "string too long" because getargs.c:PyArg_ParseTupleAndKeywords() incorrectly returns a huge value for string_len.

The problem is FETCH_ARGS is passing the wrong type to va_arg.  It grabs an "int" for the size arg, but that is the not the argument type on 64 bit platforms.  This happens to work for little endian because the low part of the 64 bit argument overlaps correctly.  Big endian is not as fortuitous.

If I change "int" to "long", the testcase succeeds.

diff -r a285ce18bd55 Python/getargs.c
--- a/Python/getargs.c	Mon May 06 18:21:10 2013 -0700
+++ b/Python/getargs.c	Tue May 07 11:26:21 2013 -0700
@@ -582,9 +582,9 @@
               char *msgbuf, size_t bufsize, PyObject **freelist)
     /* For # codes */
-#define FETCH_SIZE      int *q=NULL;Py_ssize_t *q2=NULL;\
+#define FETCH_SIZE      long *q=NULL;Py_ssize_t *q2=NULL;\
     if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \
-    else q=va_arg(*p_va, int*);
+    else q=va_arg(*p_va, long*);
 #define STORE_SIZE(s)   \
     if (flags & FLAG_SIZE_T) \
         *q2=s; \

I am not certain exactly what type it should be, but it definitely needs to be a matching 64 bit type of 64 bit platforms.

I believe that this bug exists in all versions.

components: Interpreter Core
messages: 188677
nosy: David.Edelsohn, pitrou
priority: normal
severity: normal
status: open
title: PowerLinux getargs.c FETCH_SIZE endianness bug
type: behavior
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list