Bug 626756 - test_dbm fails on ppc64 & s390x
test_dbm fails on ppc64 & s390x
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: python (Show other bugs)
6.0
All Linux
low Severity medium
: rc
: ---
Assigned To: Dave Malcolm
Petr Šplíchal
:
Depends On: 624821 627266 629274
Blocks:
  Show dependency treegraph
 
Reported: 2010-08-24 06:37 EDT by Petr Šplíchal
Modified: 2016-05-31 21:47 EDT (History)
1 user (show)

See Also:
Fixed In Version: python-2.6.6-2.el6
Doc Type: Bug Fix
Doc Text:
Previously, the "in" operator for dbm mappings erroneously returned False for all keys on big-endian 64-bit builds of Python (ppc64 and s390x). This update fixes this issue.
Story Points: ---
Clone Of:
Environment:
Last Closed: 2011-05-19 07:36:52 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Petr Šplíchal 2010-08-24 06:37:53 EDT
Description of problem:

Running the unit test test_dbm fails on ppc64 & s390x archs.

Version-Release number of selected component (if applicable):
python-2.6.5-3.el6.s390x

Steps to Reproduce:
# ./regrtest.py test_dbm.py

test_dbm
test test_dbm failed -- Traceback (most recent call last):
  File "/usr/lib64/python2.6/test/test_dbm.py", line 24, in test_keys
    self.assert_(k in self.d)
AssertionError

1 test failed:
    test_dbm
[psss@auto-s390-002 test]$ ./regrtest.py test_dbm.py
test_dbm
test test_dbm failed -- Traceback (most recent call last):
  File "/usr/lib64/python2.6/test/test_dbm.py", line 24, in test_keys
    self.assert_(k in self.d)
AssertionError

1 test failed:
    test_dbm
Comment 3 Dave Malcolm 2010-08-25 15:29:26 EDT
All of the various headers in gdbm-devel-1.8.0-36.el6.ppc64 define datum as:
      typedef struct {
        char *dptr;
        int   dsize;
      } datum;

Note the use of "int" for dsize.

This fragment of code in python's Modules/dbmmodule.c:dbm_contains:
          if (PyString_AsStringAndSize(v, (char **)&key.dptr,
                                       (Py_ssize_t *)&key.dsize)) {
                  return -1;
          }
assumes that
  sizeof(datum.dsize) == sizeof(Py_ssize_t)
which is not correct on these architectures; on ppc64:
(gdb) p sizeof(key.dsize)
$25 = 4
(gdb) p sizeof(Py_ssize_t)
$26 = 8

On ppc64, when PyString_AsStringAndSize writes the 0x00000000000000001 value for the ob_size of "a" to &key.dsize, I believe the 0x00000000 part is written to &key.size, and the 0x00000001 part is written to the 4 bytes following it, due to the incorrect cast from (int*) to (Py_ssize_t*)

Thankfully
(gdb) p sizeof(key)
$28 = 16
so I believe it writes this value to padding within the "datum key", rather than corrupting the stack.

The dbm_fetch() is thus invoked with a 0 dsize, and doesn't find the key, hence the test fails.

The various other uses with that source file appear correct:
(i) there are various PyArg_Parse* calls using s#, with int, which is correct, given the absence of the PY_SSIZE_T_CLEAN macro.
(ii) there are various calls of PyString_FromStringAndSize(, datum.dsize), which I believe is correct: I believe the compiler will coerce this int to the wider Py_ssize_t type.
Comment 4 Dave Malcolm 2010-08-25 16:06:53 EDT
Filed upstream as http://bugs.python.org/issue9687, with a patch
Comment 8 Laura Bailey 2011-05-09 20:36:58 EDT
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Previously, the "in" operator for dbm mappings erroneously returned False for all keys on big-endian 64-bit builds of Python (ppc64 and s390x). This update fixes this issue.
Comment 9 errata-xmlrpc 2011-05-19 07:36:52 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2011-0554.html
Comment 10 errata-xmlrpc 2011-05-19 09:07:33 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2011-0554.html

Note You need to log in before you can comment on or make changes to this bug.