mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
fix: cap what a rolling data tree may write
A followed member is written up to twice its listed size plus 16 MiB, and the whole tree up to twice its listed total plus 16 MiB: a source serving gigabytes where the list records kilobytes fills no drive.
This commit is contained in:
1 parent
ff69210b18
commit
a92d81c385
6 files changed
+66
-12
No files matched your search
+1
-1
@@ -16,7 +16,7 @@
|
||||
# and Invoke-WebRequest throws on a cut transfer before the hash is read:
|
||||
# the site's build rewrites this line there (scripts/sitebootstrap.py).
|
||||
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
|
||||
$defaultInstallSha256 = "3663191134988402971a3d0ae0860d6fbf158496ca03a41ff11efa4dd7a1a25b"
|
||||
$defaultInstallSha256 = "fef479226ae2eb2d35e83e78357c4a0fe1931133400ed2e82070c5910be2da74"
|
||||
# The pin above refuses any changed byte: this cap only stops a body that
|
||||
# cannot be the installer (a sign-in portal's page) before it is hashed.
|
||||
$maximumInstallerBytes = 8MB
|
||||
|
||||
+17
-1
@@ -17003,6 +17003,9 @@ def install_data_directory(entry: dict, bios_path: Path,
|
||||
written: list[dict] = []
|
||||
not_kept: list[tuple[str, str]] = []
|
||||
tallies = {"installed": 0, "updated": 0, "changed": 0}
|
||||
# What a rolling tree may write in all: a nightly grows from one build to
|
||||
# the next, never to a drive's worth. The space check counted the list.
|
||||
budget = [_follow_cap(sum(meta["size"] for meta in needed.values()))]
|
||||
# From a pack, the pack's copy is the tree: nothing newer to follow.
|
||||
rolling = bool(entry.get("rolling")) and LOCAL.pack is None
|
||||
counts: dict[str, object] = {
|
||||
@@ -17041,9 +17044,10 @@ def install_data_directory(entry: dict, bios_path: Path,
|
||||
# expected size whatever the member claims, so a member that
|
||||
# inflates without end costs one byte past it. A rolling
|
||||
# source's member is cut at the size its archive declares.
|
||||
if declared != meta["size"] and not (rolling and 0 <= declared <= MAX_DOWNLOAD_SIZE):
|
||||
if declared != meta["size"] and not (rolling and _followable(meta, declared, budget)):
|
||||
tallies["changed"] += 1
|
||||
continue
|
||||
budget[0] -= declared
|
||||
target = _destination_path(root, rel)
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
slot = _slot(entry, rel)
|
||||
@@ -17086,6 +17090,18 @@ def install_data_directory(entry: dict, bios_path: Path,
|
||||
return counts
|
||||
|
||||
|
||||
def _follow_cap(listed: int) -> int:
|
||||
"""The most a rolling source may serve where the list records listed
|
||||
bytes: twice as much, and 16 MiB more for a file that was tiny."""
|
||||
return min(2 * listed + 16 * 1024 * 1024, MAX_DOWNLOAD_SIZE)
|
||||
|
||||
|
||||
def _followable(meta: dict, declared: int, budget: list[int]) -> bool:
|
||||
"""Whether a rolling source's member of declared bytes is written: within
|
||||
its own cap and what the tree has left to write."""
|
||||
return 0 <= declared <= min(_follow_cap(meta["size"]), budget[0])
|
||||
|
||||
|
||||
def _install_data_member(
|
||||
opener: Callable[[], ContextManager[IO[bytes]]], meta: dict, target: Path,
|
||||
bios_path: Path, slot: str, rel: str, not_kept: list[tuple[str, str]],
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
|
||||
# curl or wget stop on a cut transfer before the hash is read: the site's
|
||||
# build rewrites this line there (scripts/sitebootstrap.py).
|
||||
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
|
||||
DEFAULT_INSTALL_SHA256="3663191134988402971a3d0ae0860d6fbf158496ca03a41ff11efa4dd7a1a25b"
|
||||
DEFAULT_INSTALL_SHA256="fef479226ae2eb2d35e83e78357c4a0fe1931133400ed2e82070c5910be2da74"
|
||||
# The pin above refuses any changed byte: this cap only stops a body that
|
||||
# cannot be the installer (a sign-in portal's page) before it is hashed.
|
||||
MAX_INSTALLER_BYTES=8388608
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
{
|
||||
"dest": "roms/ports/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1449211,
|
||||
"sha256": "3663191134988402971a3d0ae0860d6fbf158496ca03a41ff11efa4dd7a1a25b",
|
||||
"size": 1450003,
|
||||
"sha256": "fef479226ae2eb2d35e83e78357c4a0fe1931133400ed2e82070c5910be2da74",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -71,8 +71,8 @@
|
||||
"muos": {
|
||||
"archive": {
|
||||
"dest": "ARCHIVE/RetroBIOS.muxapp",
|
||||
"size": 1502836,
|
||||
"sha256": "53057fea5643cd65d1e486ec512b55fcef721215c4f5e223783c6d133a1ae4b6"
|
||||
"size": 1503628,
|
||||
"sha256": "89ff71e3f740d54e774513bec1ad88c5fff566074dcf45bb38632f75a789e1fa"
|
||||
},
|
||||
"members": [
|
||||
{
|
||||
@@ -92,8 +92,8 @@
|
||||
{
|
||||
"name": "RetroBIOS/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1449211,
|
||||
"sha256": "3663191134988402971a3d0ae0860d6fbf158496ca03a41ff11efa4dd7a1a25b",
|
||||
"size": 1450003,
|
||||
"sha256": "fef479226ae2eb2d35e83e78357c4a0fe1931133400ed2e82070c5910be2da74",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -166,8 +166,8 @@
|
||||
{
|
||||
"dest": ".config/modules/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1449211,
|
||||
"sha256": "3663191134988402971a3d0ae0860d6fbf158496ca03a41ff11efa4dd7a1a25b",
|
||||
"size": 1450003,
|
||||
"sha256": "fef479226ae2eb2d35e83e78357c4a0fe1931133400ed2e82070c5910be2da74",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
|
||||
+17
-1
@@ -327,6 +327,9 @@ def install_data_directory(entry: dict, bios_path: Path,
|
||||
written: list[dict] = []
|
||||
not_kept: list[tuple[str, str]] = []
|
||||
tallies = {"installed": 0, "updated": 0, "changed": 0}
|
||||
# What a rolling tree may write in all: a nightly grows from one build to
|
||||
# the next, never to a drive's worth. The space check counted the list.
|
||||
budget = [_follow_cap(sum(meta["size"] for meta in needed.values()))]
|
||||
# From a pack, the pack's copy is the tree: nothing newer to follow.
|
||||
rolling = bool(entry.get("rolling")) and LOCAL.pack is None
|
||||
counts: dict[str, object] = {
|
||||
@@ -365,9 +368,10 @@ def install_data_directory(entry: dict, bios_path: Path,
|
||||
# expected size whatever the member claims, so a member that
|
||||
# inflates without end costs one byte past it. A rolling
|
||||
# source's member is cut at the size its archive declares.
|
||||
if declared != meta["size"] and not (rolling and 0 <= declared <= MAX_DOWNLOAD_SIZE):
|
||||
if declared != meta["size"] and not (rolling and _followable(meta, declared, budget)):
|
||||
tallies["changed"] += 1
|
||||
continue
|
||||
budget[0] -= declared
|
||||
target = _destination_path(root, rel)
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
slot = _slot(entry, rel)
|
||||
@@ -410,6 +414,18 @@ def install_data_directory(entry: dict, bios_path: Path,
|
||||
return counts
|
||||
|
||||
|
||||
def _follow_cap(listed: int) -> int:
|
||||
"""The most a rolling source may serve where the list records listed
|
||||
bytes: twice as much, and 16 MiB more for a file that was tiny."""
|
||||
return min(2 * listed + 16 * 1024 * 1024, MAX_DOWNLOAD_SIZE)
|
||||
|
||||
|
||||
def _followable(meta: dict, declared: int, budget: list[int]) -> bool:
|
||||
"""Whether a rolling source's member of declared bytes is written: within
|
||||
its own cap and what the tree has left to write."""
|
||||
return 0 <= declared <= min(_follow_cap(meta["size"]), budget[0])
|
||||
|
||||
|
||||
def _install_data_member(
|
||||
opener: Callable[[], ContextManager[IO[bytes]]], meta: dict, target: Path,
|
||||
bios_path: Path, slot: str, rel: str, not_kept: list[tuple[str, str]],
|
||||
|
||||
@@ -4458,6 +4458,28 @@ class DataDirectoriesAreInstalled(unittest.TestCase):
|
||||
counts = install.install_data_directory({**self._entry(), "rolling": True}, bios)
|
||||
self.assertEqual((counts["installed"], counts["updated"], counts["changed"]), (0, 0, 1))
|
||||
|
||||
def test_a_rolling_member_past_its_cap_is_not_written(self):
|
||||
"""A followed member is read to the size its archive declares: a
|
||||
source serving gigabytes where the list has 3 bytes fills no drive."""
|
||||
work = Path(_tempdir(self))
|
||||
entry = {**self._entry(), "rolling": True}
|
||||
served: list[int] = []
|
||||
|
||||
def members(_archive, _entry):
|
||||
for rel, size in (("Sys/GC/dsp.bin", 900 * 1024 * 1024),
|
||||
("Sys/GC/font.bin", 4)):
|
||||
yield rel, size, lambda size=size: served.append(size) or io.BytesIO(b"font")
|
||||
|
||||
with unittest.mock.patch.object(
|
||||
install, "_fetch_archive",
|
||||
lambda url, d, progress=None, keep=None: Path(d) / "a"), \
|
||||
unittest.mock.patch.object(install, "_archive_members", members):
|
||||
counts = install.install_data_directory(entry, work)
|
||||
self.assertEqual((counts["changed"], counts["installed"]), (1, 1))
|
||||
self.assertEqual(served, [4])
|
||||
self.assertEqual(install._follow_cap(3), 16 * 1024 * 1024 + 6)
|
||||
self.assertFalse(install._followable({"size": 3}, 40, [39]))
|
||||
|
||||
def test_a_rolling_flag_is_true_or_absent(self):
|
||||
with self.assertRaisesRegex(ValueError, "rolling is invalid"):
|
||||
install._check_data_directory({**self._entry(), "rolling": False}, "d")
|
||||
|
||||
Reference in new issue
Block a user