This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
The following commit(s) were added to refs/heads/main by this push:
new 91224b4 Add unit tests for the archive member limit code
91224b4 is described below
commit 91224b4a66f6e711399fa5f9fba42239450347d3
Author: Sean B. Palmer <[email protected]>
AuthorDate: Wed Jan 28 15:25:01 2026 +0000
Add unit tests for the archive member limit code
---
tests/unit/test_archive_member_limit.py | 108 ++++++++++++++++++++++++++++++++
1 file changed, 108 insertions(+)
diff --git a/tests/unit/test_archive_member_limit.py
b/tests/unit/test_archive_member_limit.py
new file mode 100644
index 0000000..e805d68
--- /dev/null
+++ b/tests/unit/test_archive_member_limit.py
@@ -0,0 +1,108 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import io
+import tarfile
+import zipfile
+
+import pytest
+
+import atr.archives as archives
+import atr.tarzip as tarzip
+import atr.tasks.checks.zipformat as zipformat
+
+
+def test_extract_wraps_member_limit(tmp_path, monkeypatch):
+ archive_path = tmp_path / "sample.tar"
+ _make_tar(archive_path, ["a.txt", "b.txt", "c.txt"])
+ extract_dir = tmp_path / "out"
+ extract_dir.mkdir()
+
+ original_open = tarzip.open_archive
+
+ def limited_open(path: str, *args, **kwargs):
+ return original_open(path, max_members=2)
+
+ monkeypatch.setattr(tarzip, "open_archive", limited_open)
+
+ with pytest.raises(archives.ExtractionError) as excinfo:
+ archives.extract(str(archive_path), str(extract_dir), max_size=1024 *
1024, chunk_size=1024)
+
+ assert "too many members" in str(excinfo.value).lower()
+
+
+def test_open_archive_enforces_member_limit_tar(tmp_path):
+ archive_path = tmp_path / "sample.tar"
+ _make_tar(archive_path, ["a.txt", "b.txt", "c.txt"])
+
+ with tarzip.open_archive(str(archive_path), max_members=2) as archive:
+ with pytest.raises(tarzip.ArchiveMemberLimitExceededError):
+ list(archive)
+
+
+def test_open_archive_enforces_member_limit_zip(tmp_path):
+ archive_path = tmp_path / "sample.zip"
+ _make_zip(archive_path, ["a.txt", "b.txt", "c.txt"])
+
+ with tarzip.open_archive(str(archive_path), max_members=2) as archive:
+ with pytest.raises(tarzip.ArchiveMemberLimitExceededError):
+ list(archive)
+
+
+def test_zipformat_integrity_reports_member_limit(tmp_path, monkeypatch):
+ archive_path = tmp_path / "sample.zip"
+ _make_zip(archive_path, ["a.txt", "b.txt", "c.txt"])
+
+ original_open = tarzip.open_archive
+
+ def limited_open(path: str, *args, **kwargs):
+ return original_open(path, max_members=2)
+
+ monkeypatch.setattr(tarzip, "open_archive", limited_open)
+
+ result = zipformat._integrity_check_core_logic(str(archive_path))
+ assert "too many members" in result.get("error", "").lower()
+
+
+def test_zipformat_structure_reports_member_limit(tmp_path, monkeypatch):
+ archive_path = tmp_path / "sample.zip"
+ _make_zip(archive_path, ["a.txt", "b.txt", "c.txt"])
+
+ original_open = tarzip.open_archive
+
+ def limited_open(path: str, *args, **kwargs):
+ return original_open(path, max_members=2)
+
+ monkeypatch.setattr(tarzip, "open_archive", limited_open)
+
+ result = zipformat._structure_check_core_logic(str(archive_path))
+ assert "too many members" in result.get("error", "").lower()
+
+
+def _make_tar(path, members: list[str]) -> None:
+ with tarfile.open(path, "w") as tf:
+ for name in members:
+ data = f"data-{name}".encode()
+ info = tarfile.TarInfo(name=name)
+ info.size = len(data)
+ tf.addfile(info, io.BytesIO(data))
+
+
+def _make_zip(path, members: list[str]) -> None:
+ with zipfile.ZipFile(path, "w") as zf:
+ for name in members:
+ zf.writestr(name, f"data-{name}")
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]