Skip to content

os.getcwd fails for long path names on linux #46974

Closed

Description

@exarkun
mannequin
BPO 2722
Nosy @birkenfeld, @facundobatista, @gpshead, @amauryfa, @giampaolo, @tiran, @smurfix
Files
  • python-getcwd-dual-strategy.patch: Patch for stack/malloc dual strategy for getcwd
  • python-getcwd-malloconly.patch: Patch for using malloc exclusively with getcwd
  • python-getcwd-test_longpathnames.patch: Patch to add a test for long path names with getcwd
  • 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 2008-06-22.13:37:12.111>
    created_at = <Date 2008-04-30.00:01:51.549>
    labels = ['easy', 'library']
    title = 'os.getcwd fails for long path names on linux'
    updated_at = <Date 2009-09-02.02:59:47.684>
    user = 'https://bugs.python.org/exarkun'

    bugs.python.org fields:

    activity = <Date 2009-09-02.02:59:47.684>
    actor = 'boya'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-06-22.13:37:12.111>
    closer = 'facundobatista'
    components = ['Library (Lib)']
    creation = <Date 2008-04-30.00:01:51.549>
    creator = 'exarkun'
    dependencies = []
    files = ['10240', '10241', '10250']
    hgrepos = []
    issue_num = 2722
    keywords = ['patch', 'easy']
    message_count = 10.0
    messages = ['65987', '66021', '66022', '66370', '66519', '66531', '68563', '92145', '92150', '92152']
    nosy_count = 10.0
    nosy_names = ['georg.brandl', 'facundobatista', 'gregory.p.smith', 'exarkun', 'amaury.forgeotdarc', 'giampaolo.rodola', 'christian.heimes', 'smurfix', 'nbm', 'boya']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue2722'
    versions = ['Python 2.5', 'Python 2.4']

    Activity

    1. exarkun commented on Apr 30, 2008

      exarkunmannequin
      MannequinAuthor
      $ python -c "print len('`pwd`'); import os; print os.getcwd()"
      1174
      Traceback (most recent call last):
        File "<string>", line 1, in ?
      OSError: [Errno 34] Numerical result out of range
      $

      The getcwd man page documents the ERANGE failure and suggests that the
      calling application allocate a larger buffer and try again.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Apr 30, 2008
    3. birkenfeld commented on Apr 30, 2008

      @birkenfeld
      Member

      Why isn't the buffer length MAX_PATH anyway?

    4. tiran commented on Apr 30, 2008

      @tiran
      Member

      It should be MAX_PATH. All path related functions should use MAX_PATH as
      buffer size, maybe even MAX_PATH+1

    5. smurfix commented on May 7, 2008

      smurfixmannequin
      Mannequin

      MAX_PATH is a compile time constant which, like FD_BITS for select(),
      may be too small for the system you're ultimately running on.

      Using that as default initial size is OK, but handling ERANGE is still a
      very good idea.

    6. nbm commented on May 10, 2008

      nbmmannequin
      Mannequin

      This affects OS X too.

      I'm attaching two patches - one uses malloc to build a bigger string if
      the existing implementation returns ERANGE, and the other one uses
      malloc from the start. This was done on the theory that stack memory
      use would be better/more efficient. However, based on testing, there's
      no real difference - 16.8usec vs. 17usec - on a rarely-used function.

    7. nbm commented on May 10, 2008

      nbmmannequin
      Mannequin

      Here's a patch to add a test that fails with Python 2.5 on OS X, but
      passes with either of these patches.

    8. facundobatista commented on Jun 22, 2008

      @facundobatista
      Member

      Went for the malloc only patch. Just fixed a small detail (weird corner
      case if malloc returned NULL first time, res will be unassigned).

      The test could be better (no necessity of using a recursive function, it
      could be done with a while), but it works.

      Commited in r64452.

    9. boya commented on Sep 1, 2009

      boyamannequin
      Mannequin

      This bug occurred in posix_getcwd() and is being fixed.
      Should the following code in posix_getcwdu() also be fixed the same way?

      posix_getcwdu(PyObject *self, PyObject *noargs)
      {
      	char buf[1026];
              ...
      #if defined(PYOS_OS2) && defined(PYCC_GCC)
      	res = _getcwd2(buf, sizeof buf);
      #else
      	res = getcwd(buf, sizeof buf);
      #endif
              ...
      }

      In my opinion, the fixed length buf should be discarded and instead
      allocate memory to buf as needed (as the fix code in posix_getcwd()),
      since getcwd() does not have a maximum anymore.

    10. amauryfa commented on Sep 2, 2009

      @amauryfa
      Contributor

      Please open a new issue; and a patch is welcome.

    11. boya commented on Sep 2, 2009

      boyamannequin
      Mannequin

      Amaury,

      Created bpo-6817 with a patch.

    12. 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

      easystdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions