diff --git a/mercurial/cext/dirs.c b/mercurial/cext/dirs.c --- a/mercurial/cext/dirs.c +++ b/mercurial/cext/dirs.c @@ -66,6 +66,11 @@ while ((pos = _finddir(cpath, pos - 1)) != -1) { PyObject *val; + // Sniff for trailing slashes, a marker of an invalid input. + if (cpath[pos] == '/') { + goto bail; + } + key = PyBytes_FromStringAndSize(cpath, pos); if (key == NULL) goto bail;