Handle APT epoch URI encoding without double-decoding package filenames

This commit is contained in:
Andrei Smaliak 2026-09-14 12:10:29 +02:00
parent dcbc39550a
commit afe749fc1b
2 changed files with 20 additions and 6 deletions

View File

@ -138,6 +138,7 @@ def bootstrap(url, branch, checkout):
p.parent.mkdir(parents=True, exist_ok=True) p.parent.mkdir(parents=True, exist_ok=True)
p.write_bytes(data) p.write_bytes(data)
p.chmod(int(entry['mode'][-3:], 8)) p.chmod(int(entry['mode'][-3:], 8))
print('Fetching', len(files), 'installer/metadata files; package payloads excluded', flush=True)
with ThreadPoolExecutor(max_workers=6) as pool: with ThreadPoolExecutor(max_workers=6) as pool:
list(pool.map(download, files)) list(pool.map(download, files))
source = {'repo': repo, 'commit': commit, 'branch': branch, 'files': files} source = {'repo': repo, 'commit': commit, 'branch': branch, 'files': files}
@ -281,6 +282,18 @@ def message(code, fields):
print(k + ': ' + str(v).replace('\n', ' ').replace('\r', ' ')) print(k + ': ' + str(v).replace('\n', ' ').replace('\r', ' '))
print('', flush=True) print('', flush=True)
def apt_key(uri, objects):
u = urllib.parse.urlparse(uri)
if u.scheme != 'iomatex' or u.netloc != HOST or u.query or u.fragment:
raise ValueError('Unsupported APT source')
# APT's method protocol may already decode the URI displayed by apt-get.
# Preserve literal %3a in Git filenames; never decode it twice into an epoch colon.
for path in (u.path, urllib.parse.unquote(u.path)):
key = safe_path(path.lstrip('/'))
if key in ('Packages', 'Packages.gz') or key in objects:
return key
raise FileNotFoundError('File absent from the pinned Git catalog')
def apt_method(): def apt_method():
def stopped(signum, frame): def stopped(signum, frame):
raise SystemExit(0) raise SystemExit(0)
@ -308,12 +321,7 @@ def apt_method():
if not first.startswith('600 '): continue if not first.startswith('600 '): continue
uri, filename = fields.get('URI', ''), fields.get('Filename', '') uri, filename = fields.get('URI', ''), fields.get('Filename', '')
try: try:
u = urllib.parse.urlparse(uri) key = apt_key(uri, config['objects'])
if u.scheme != 'iomatex' or u.netloc != HOST or u.query or u.fragment:
raise ValueError('Unsupported APT source')
key = safe_path(urllib.parse.unquote(u.path).lstrip('/'))
if key not in ('Packages', 'Packages.gz') and key not in config['objects']:
raise FileNotFoundError('File absent from the pinned Git catalog')
message('200 URI Start', {'URI':uri}) message('200 URI Start', {'URI':uri})
if key in ('Packages', 'Packages.gz'): if key in ('Packages', 'Packages.gz'):
data = (STATE / key).read_bytes() data = (STATE / key).read_bytes()

View File

@ -49,6 +49,12 @@ class DeliveryTest(unittest.TestCase):
(root/'.iomatex-source.json').write_text(json.dumps({'files':[{'path':'local_installer.sh','sha':d.blob_hash(b'original')}]})) (root/'.iomatex-source.json').write_text(json.dumps({'files':[{'path':'local_installer.sh','sha':d.blob_hash(b'original')}]}))
with self.assertRaisesRegex(ValueError,'Local change'): d.check_existing(root) with self.assertRaisesRegex(ValueError,'Local change'): d.check_existing(root)
def test_apt_epoch_filename_decoded_only_once(self):
key='debian/xserver-common_2%3a1.0+deb11_all.deb'
objects={key:{}}
for path in [key, 'debian/xserver-common_2%253a1.0%2bdeb11_all.deb']:
self.assertEqual(key,d.apt_key('iomatex://git.it-screen.com/'+path,objects))
def test_no_redirect_even_on_same_host(self): def test_no_redirect_even_on_same_host(self):
with self.assertRaisesRegex(ValueError,'redirect refused'): with self.assertRaisesRegex(ValueError,'redirect refused'):
d.NoRedirect().redirect_request(None,None,302,'',{},'https://git.it-screen.com/other') d.NoRedirect().redirect_request(None,None,302,'',{},'https://git.it-screen.com/other')