|
1 | 1 | import contextlib |
2 | 2 | import importlib.util |
3 | 3 | import io |
| 4 | +import gzip |
4 | 5 | import json |
5 | 6 | import os |
6 | 7 | import tarfile |
@@ -276,6 +277,30 @@ def test_unsafe_archive_variants_never_create_binary(self): |
276 | 277 | with self.assertRaises(ValueError): |
277 | 278 | s.extract_binary(archive, output) |
278 | 279 | self.assertFalse(output.exists()) |
| 280 | + member = tarfile.TarInfo('telemt') |
| 281 | + member.size = 128 * 1024 * 1024 + 1 |
| 282 | + with gzip.open(archive, 'wb') as compressed: |
| 283 | + compressed.write(member.tobuf() + b'\0' * 1024) |
| 284 | + with self.assertRaises(ValueError): |
| 285 | + s.extract_binary(archive, output) |
| 286 | + self.assertFalse(output.exists()) |
| 287 | + |
| 288 | + @unittest.skipUnless(os.name == 'posix', 'Unix flags checked on Linux CI') |
| 289 | + def test_archive_output_symlink_does_not_overwrite_target(self): |
| 290 | + with tempfile.TemporaryDirectory() as tmp: |
| 291 | + root = Path(tmp) |
| 292 | + target = root/'target' |
| 293 | + target.write_bytes(b'unchanged') |
| 294 | + output = root/'binary' |
| 295 | + output.symlink_to(target) |
| 296 | + archive = root/'asset.tar.gz' |
| 297 | + with tarfile.open(archive, 'w:gz') as tar: |
| 298 | + member = tarfile.TarInfo('telemt') |
| 299 | + member.size = 7 |
| 300 | + tar.addfile(member, io.BytesIO(b'fixture')) |
| 301 | + with self.assertRaises(OSError): |
| 302 | + s.extract_binary(archive, output) |
| 303 | + self.assertEqual(target.read_bytes(), b'unchanged') |
279 | 304 |
|
280 | 305 | @unittest.skipUnless(os.name == 'posix', 'Unix permissions checked on Linux CI') |
281 | 306 | def test_symlink_and_writable_ancestor_refused(self): |
|
0 commit comments