[New-bugs-announce] [issue46606] Large C stack usage of os.getgroups() and os.setgroups()

Inada Naoki report at bugs.python.org
Tue Feb 1 22:06:44 EST 2022

New submission from Inada Naoki <songofacandy at gmail.com>:

I checked stack usage for bpo-46600 and found this two functions use a lot of stack.

os_setgroups: 262200 bytes
os_getgroups_impl: 262184 bytes

Both function has local variable like this:

    gid_t grouplist[MAX_GROUPS];

MAX_GROUPS is defined as:

    /* defined to be 16 on Solaris7, so this should be a small number */
#define MAX_GROUPS 64

NGROUPS_MAX is 65536 and sizeof(gid_t) is 4 on Ubuntu 20.04, so grouplist is 262144bytes.

It seems this grouplist is just for avoid allocation:

    } else if (n <= MAX_GROUPS) {
        /* groups will fit in existing array */
        alt_grouplist = grouplist;
    } else {
        alt_grouplist = PyMem_New(gid_t, n);
        if (alt_grouplist == NULL) {
            return PyErr_NoMemory();

How about just using `#define MAX_GROUPS 64`?
Or should we remove this grouplist because os.grouplist() is not called so frequently?

components: Library (Lib)
messages: 412335
nosy: methane
priority: normal
severity: normal
status: open
title: Large C stack usage of os.getgroups() and os.setgroups()
versions: Python 3.11

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list