Bug 626756 - test_dbm fails on ppc64 & s390x
Summary: test_dbm fails on ppc64 & s390x
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: python (Show other bugs)
(Show other bugs)
Version: 6.0
Hardware: All Linux
low
medium
Target Milestone: rc
: ---
Assignee: Dave Malcolm
QA Contact: Petr Šplíchal
URL:
Whiteboard:
Keywords:
Depends On: 624821 627266 629274
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-08-24 10:37 UTC by Petr Šplíchal
Modified: 2016-06-01 01:47 UTC (History)
1 user (show)

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 11:36:52 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2011:0554 normal SHIPPED_LIVE Moderate: python security, bug fix, and enhancement update 2011-05-19 11:35:29 UTC

Description Petr Šplíchal 2010-08-24 10:37:53 UTC
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 19:29:26 UTC
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 20:06:53 UTC
Filed upstream as http://bugs.python.org/issue9687, with a patch

Comment 8 Laura Bailey 2011-05-10 00:36:58 UTC
    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 11:36:52 UTC
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 13:07:33 UTC
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.