Skip to content

Commit

Permalink
Merge branch '3.9' into backport-f7bfac4-3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
encukou authored Oct 29, 2024
2 parents cbbf2b9 + bbe8756 commit c8eeb4c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
54 changes: 39 additions & 15 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import errno
import sys
import os
import io
Expand Down Expand Up @@ -3651,34 +3652,55 @@ def test_modes(self):
arc.add('read_group_only', mode='?---r-----')
arc.add('no_bits', mode='?---------')
arc.add('dir/', mode='?---rwsrwt')
arc.add('dir_all_bits/', mode='?rwsrwsrwt')

# On some systems, setting the sticky bit is a no-op.
# Check if that's the case.
# On some systems, setting the uid, gid, and/or sticky bit is a no-ops.
# Check which bits we can set, so we can compare tarfile machinery to
# a simple chmod.
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
with open(tmp_filename, 'w'):
pass
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
os.unlink(tmp_filename)
try:
new_mode = (os.stat(tmp_filename).st_mode
| stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
try:
os.chmod(tmp_filename, new_mode)
except OSError as exc:
if exc.errno == getattr(errno, "EFTYPE", 0):
# gh-108948: On FreeBSD, regular users cannot set
# the sticky bit.
self.skipTest("chmod() failed with EFTYPE: "
"regular users cannot set sticky bit")
else:
raise

got_mode = os.stat(tmp_filename).st_mode
_t_file = 't' if (got_mode & stat.S_ISVTX) else 'x'
_suid_file = 's' if (got_mode & stat.S_ISUID) else 'x'
_sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x'
finally:
os.unlink(tmp_filename)

os.mkdir(tmp_filename)
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
have_sticky_dirs = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
new_mode = (os.stat(tmp_filename).st_mode
| stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
os.chmod(tmp_filename, new_mode)
got_mode = os.stat(tmp_filename).st_mode
_t_dir = 't' if (got_mode & stat.S_ISVTX) else 'x'
_suid_dir = 's' if (got_mode & stat.S_ISUID) else 'x'
_sgid_dir = 's' if (got_mode & stat.S_ISGID) else 'x'
os.rmdir(tmp_filename)

with self.check_context(arc.open(), 'fully_trusted'):
if have_sticky_files:
self.expect_file('all_bits', mode='?rwsrwsrwt')
else:
self.expect_file('all_bits', mode='?rwsrwsrwx')
self.expect_file('all_bits',
mode=f'?rw{_suid_file}rw{_sgid_file}rw{_t_file}')
self.expect_file('perm_bits', mode='?rwxrwxrwx')
self.expect_file('exec_group_other', mode='?rw-rwxrwx')
self.expect_file('read_group_only', mode='?---r-----')
self.expect_file('no_bits', mode='?---------')
if have_sticky_dirs:
self.expect_file('dir/', mode='?---rwsrwt')
else:
self.expect_file('dir/', mode='?---rwsrwx')
self.expect_file('dir/', mode=f'?---rw{_sgid_dir}rw{_t_dir}')
self.expect_file('dir_all_bits/',
mode=f'?rw{_suid_dir}rw{_sgid_dir}rw{_t_dir}')

with self.check_context(arc.open(), 'tar'):
self.expect_file('all_bits', mode='?rwxr-xr-x')
Expand All @@ -3687,6 +3709,7 @@ def test_modes(self):
self.expect_file('read_group_only', mode='?---r-----')
self.expect_file('no_bits', mode='?---------')
self.expect_file('dir/', mode='?---r-xr-x')
self.expect_file('dir_all_bits/', mode='?rwxr-xr-x')

with self.check_context(arc.open(), 'data'):
normal_dir_mode = stat.filemode(stat.S_IMODE(
Expand All @@ -3697,6 +3720,7 @@ def test_modes(self):
self.expect_file('read_group_only', mode='?rw-r-----')
self.expect_file('no_bits', mode='?rw-------')
self.expect_file('dir/', mode=normal_dir_mode)
self.expect_file('dir_all_bits/', mode=normal_dir_mode)

def test_pipe(self):
# Test handling of a special file
Expand Down
21 changes: 19 additions & 2 deletions Lib/test/test_zlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from test import support
import binascii
import copy
import os
import pickle
import random
import sys
Expand Down Expand Up @@ -30,6 +31,16 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()


# bpo-46623: When a hardware accelerator is used (currently only on s390x),
# using different ways to compress data with zlib can produce different
# compressed data.
#
# To simplify the skip condition, make the assumption that s390x always has an
# accelerator, and nothing else has it.
# Windows doesn't have os.uname() but it doesn't support s390x.
HW_ACCELERATED = hasattr(os, 'uname') and os.uname().machine == 's390x'


class VersionTestCase(unittest.TestCase):

def test_library_version(self):
Expand Down Expand Up @@ -191,7 +202,10 @@ def test_speech128(self):
# compress more data
data = HAMLET_SCENE * 128
x = zlib.compress(data)
self.assertEqual(zlib.compress(bytearray(data)), x)
# With hardware acceleration, the compressed bytes
# might not be identical.
if not HW_ACCELERATED:
self.assertEqual(zlib.compress(bytearray(data)), x)
for ob in x, bytearray(x):
self.assertEqual(zlib.decompress(ob), data)

Expand Down Expand Up @@ -248,7 +262,10 @@ def test_pair(self):
x1 = co.compress(data)
x2 = co.flush()
self.assertRaises(zlib.error, co.flush) # second flush should not work
self.assertEqual(x1 + x2, datazip)
# With hardware acceleration, the compressed bytes might not
# be identical.
if not HW_ACCELERATED:
self.assertEqual(x1 + x2, datazip)
for v1, v2 in ((x1, x2), (bytearray(x1), bytearray(x2))):
dco = zlib.decompressobj()
y1 = dco.decompress(v1 + v2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Re-enable skipped tests for :mod:`zlib` on the s390x architecture: only skip
checks of the compressed bytes, which can be different between zlib's
software implementation and the hardware-accelerated implementation.

0 comments on commit c8eeb4c

Please sign in to comment.