Skip to content

locale.strxfrm raises MemoryError #51329

Closed

Description

@drukker
mannequin
BPO 7080
Nosy @loewis, @pitrou
Files
  • strxfrm_MemoryError.patch
  • strxfrm_fixes_and_collation_tests.patch
  • strxfrm_fixes_and_collation_tests_2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2009-10-19.19:49:59.948>
    created_at = <Date 2009-10-07.23:01:41.779>
    labels = ['extension-modules', 'type-crash']
    title = 'locale.strxfrm raises MemoryError'
    updated_at = <Date 2009-10-19.19:49:59.946>
    user = 'https://bugs.python.org/drukker'

    bugs.python.org fields:

    activity = <Date 2009-10-19.19:49:59.946>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-10-19.19:49:59.948>
    closer = 'pitrou'
    components = ['Extension Modules']
    creation = <Date 2009-10-07.23:01:41.779>
    creator = 'drukker'
    dependencies = []
    files = ['15078', '15158', '15167']
    hgrepos = []
    issue_num = 7080
    keywords = ['patch']
    message_count = 10.0
    messages = ['93728', '94079', '94085', '94092', '94186', '94242', '94254', '94255', '94256', '94258']
    nosy_count = 3.0
    nosy_names = ['loewis', 'pitrou', 'drukker']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue7080'
    versions = ['Python 3.1', 'Python 3.2']

    Activity

    1. drukker commented on Oct 7, 2009

      drukkermannequin
      MannequinAuthor

      The strxfrm function in the locale module can potentially raise a
      MemoryError.

      The failing malloc is in Modules/_localemodule.c, line 291.

      This is because the variable n0 of type Py_ssize_t is passed to
      PyArg_ParseTuple, which expects an int when PY_SSIZE_T_CLEAN is not defined.

      Patch attached, which also fixes an unrelated memory leak.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Oct 7, 2009
    3. drukker commented on Oct 15, 2009

      drukkermannequin
      MannequinAuthor

      Could someone triage this? And review my simple fix? I think it should
      be a release blocker.

      It seems to me to be a problem on all 64-bit non-Windows platforms, or
      any platform if using UCS-4. The 4 high-order bytes of an 8-byte
      Py_ssize_t variable are not initialized.

      Thanks.

    4. added and removed
      stdlibStandard Library Python modules in the Lib/ directory
      on Oct 15, 2009
    5. pitrou commented on Oct 15, 2009

      @pitrou
      Member

      Nice catch. I wonder why not all of our modules are PY_SSIZE_T_CLEAN in
      py3k.
      This function is not actually tested, could you add a test to the
      regression suite?

    6. drukker commented on Oct 15, 2009

      drukkermannequin
      MannequinAuthor

      All right.

      The function strcoll also isn't tested (except for issue bpo-3303). I'll
      look into that one, too.

    7. drukker commented on Oct 17, 2009

      drukkermannequin
      MannequinAuthor

      I've added the tests.

      I found that on Windows, strxfrm has been unavailable in py3k since
      r61306, because of an omission in PC/pyconfig.h. (cf. patch)

      In determining whether I should first test for the existence of strcoll
      (or strxfrm) in the locale module, as was done in TestMiscellaneous, I
      found this is no longer needed in py3k since r61339. (cf. patch) (In
      python2 such checks are still necessary.)

    8. drukker commented on Oct 19, 2009

      drukkermannequin
      MannequinAuthor

      The tests in TestEnUSCollation I added don't work for all encodings
      (e.g. Asian ones, or ASCII). Now checked for encodings which are known
      to work.

      Found and fixed a bug (result not returned) in getpreferredencoding in
      Lib/locale.py.

      This test is skipped on Mac, since r30377. I've tested it on 10.3
      (PPC), and it passed, so I enabled it again.

      I did, however, find that FreeBSD and Mac OS X have known bugs in
      wcscoll and wcsxfrm: http://www.freebsd.org/cgi/man.cgi?query=wcsxfrm
      (cf. patch)

    9. pitrou commented on Oct 19, 2009

      @pitrou
      Member

      Nice work, thanks!
      One detail: when giving you credit, who should I mention? just "egreen"?

    10. drukker commented on Oct 19, 2009

      drukkermannequin
      MannequinAuthor

      I've entered my real name.

    11. pitrou commented on Oct 19, 2009

      @pitrou
      Member

      Ok, thanks.

    12. pitrou commented on Oct 19, 2009

      @pitrou
      Member

      The patch is now committed to py3k (r75539) and 3.1 (r75541), closing.

    13. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      extension-modulesC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dump

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions