Skip to content

Commit 8376908

Browse files
committed
Revert "gh-146121: pkgutil.get_data() reject invalid resource arguments (#146122)"
This reverts commit bcdf231.
1 parent 5e9d90b commit 8376908

File tree

3 files changed

+0
-25
lines changed

3 files changed

+0
-25
lines changed

Lib/pkgutil.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,6 @@ def get_data(package, resource):
393393
# signature - an os.path format "filename" starting with the dirname of
394394
# the package's __file__
395395
parts = resource.split('/')
396-
if os.path.isabs(resource) or '..' in parts:
397-
raise ValueError("resource must be a relative path with no "
398-
"parent directory components")
399396
parts.insert(0, os.path.dirname(mod.__file__))
400397
resource_name = os.path.join(*parts)
401398
return loader.get_data(resource_name)

Lib/test/test_pkgutil.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,6 @@ def test_getdata_filesys(self):
6161

6262
del sys.modules[pkg]
6363

64-
def test_getdata_path_traversal(self):
65-
pkg = 'test_getdata_traversal'
66-
67-
# Make a package with some resources
68-
package_dir = os.path.join(self.dirname, pkg)
69-
os.mkdir(package_dir)
70-
# Empty init.py
71-
f = open(os.path.join(package_dir, '__init__.py'), "wb")
72-
f.close()
73-
74-
with self.assertRaises(ValueError):
75-
pkgutil.get_data(pkg, '../../../etc/passwd')
76-
with self.assertRaises(ValueError):
77-
pkgutil.get_data(pkg, 'sub/../../../etc/passwd')
78-
with self.assertRaises(ValueError):
79-
pkgutil.get_data(pkg, os.path.abspath('/etc/passwd'))
80-
81-
del sys.modules[pkg]
82-
8364
def test_getdata_zipfile(self):
8465
zip = 'test_getdata_zipfile.zip'
8566
pkg = 'test_getdata_zipfile'

Misc/NEWS.d/next/Security/2026-03-16-18-07-00.gh-issue-146121.vRbdro.rst

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)