Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

tools: b64push.py leaves room for the staging path, so a long one no longer overflows native ADB

Tom Whitwell4aec5a9b8dae
diff --git a/tests/test_b64push_atomic.py b/tests/test_b64push_atomic.py
index 681168389..ce53580cd 100644
--- a/tests/test_b64push_atomic.py
+++ b/tests/test_b64push_atomic.py
@@ -121,6 +121,17 @@ class B64PushTest(TempDirTest):
for command in self.commands():
self.assertIn(f"'{target}", command, "every remote path is single-quoted")
+ def test_every_command_fits_one_payload_with_a_long_remote_path(self):
+ # tools/theme.sh stages a wallpaper at /data/local/tmp/cyt-theme-wallpapers-<name>.jpg. Over native adb
+ # (a 4096-byte payload) a chunk sized without that path made `echo '<chunk>' >> <path>` too long:
+ # "shell command too long", and no picture of the theme reached the TV.
+ data = os.urandom(20000)
+ target = self.remote_dir / ("x" * 40 + ".jpg")
+ result = self.push(str(self.local(data)), str(target))
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(target.read_bytes(), data)
+ self.assertLessEqual(max(len(c) for c in self.commands()), 4096)
+
def test_failed_checksum_leaves_the_original_intact(self):
target = self.remote_dir / "file.apk"
target.write_bytes(b"old contents")
diff --git a/tools/b64push.py b/tools/b64push.py
index 98cb1b1ba..f7870ddd9 100644
--- a/tools/b64push.py
+++ b/tools/b64push.py
@@ -94,7 +94,8 @@ def main():
b64 = remote + ".b64.part"
part = remote + ".part"
try:
- chunk = min(CHUNK, dev.max_chunk_size * 3 // 4 - 64) # base64 of the chunk plus the echo must fit one payload
+ # base64 of the chunk plus the echo (which names the staging file) must fit one payload
+ chunk = min(CHUNK, (dev.max_chunk_size - 85 - len(b64)) * 3 // 4)
chunk -= chunk % 3 # a multiple of 3, or each chunk ends in '=' padding mid-stream and base64 -d corrupts it
# Only our own temporary names are cleared; the target stays until the copy is verified.
# `: >` creates the base64 file even for an empty upload, so `base64 -d` has an input.