Skip to contentSkip to conversation

[2.8][PATCH 0/4] Pull request

bitbake Yoann Congal 1 participant 5 messages Jun 5

lore
Share & tools
lore
#0 lore raw

Passed a-full on autobuilder:
https://autobuilder.yoctoproject.org/valkyrie/#/builders/29/builds/3933

The following changes since commit 82abbfcdbda949851a03bb2cb2049ea689564ad6:

tests/fetch: Avoid using git protocol in tests (2026-05-13 22:22:20 +0200)

are available in the Git repository at:

https://git.openembedded.org/bitbake-contrib stable/2.8-next
https://git.openembedded.org/bitbake-contrib/log/?h=stable/2.8-next

for you to fetch changes up to 37beb06ba9329cd16976273efbb341f781d4e749:

  fetch2: Unpack RPMs with --no-absolute-filenames (2026-06-05 12:50:29 +0200)

----------------------------------------------------------------

Anders Heimer (4):
fetch2: validate deb/ipk data member names
fetch2: validate striplevel parameter fetch2/git: quote shallow extra ref arguments
fetch2: Unpack RPMs with --no-absolute-filenames

 lib/bb/fetch2/__init__.py | 19 +++++---
 lib/bb/fetch2/git.py      |  2 +-
 lib/bb/tests/fetch.py     | 94 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+), 7 deletions(-)
#1 lore raw

[bitbake][scarthgap][2.8][PATCH 4/4] fetch2: Unpack RPMs with --no-absolute-filenames

From: Anders Heimer <[email protected]>

Use cpio --no-absolute-filenames when unpacking RPM and SRPM archives so absolute paths and parent-directory components in cpio member names are extracted relative to the intended unpack directory.

(cherry picked from commit 1b1a71586aa93678c1d9ca40ef2c6fa518f89356)
---
 lib/bb/fetch2/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/bb/fetch2/__init__.py +2 -2
index 7f6cf8ba9..f2835397a 100644
@@ -1563,11 +1563,11 @@ class FetchMethod(object):
             elif file.endswith('.rpm') or file.endswith('.srpm'):
                 if 'extract' in urldata.parm:
                     unpack_file = urldata.parm.get('extract')
-                    cmd = 'rpm2cpio.sh %s | cpio -id %s' % (file, unpack_file)
+                    cmd = 'rpm2cpio.sh %s | cpio --no-absolute-filenames -id %s' % (file, unpack_file)
                     iterate = True
                     iterate_file = unpack_file
                 else:
-                    cmd = 'rpm2cpio.sh %s | cpio -id' % (file)
+                    cmd = 'rpm2cpio.sh %s | cpio --no-absolute-filenames -id' % (file)
             elif file.endswith('.deb') or file.endswith('.ipk'):
                 output = subprocess.check_output(['ar', '-t', file], preexec_fn=subprocess_setup)
                 datafile = None
#2 lore raw

[bitbake][scarthgap][2.8][PATCH 2/4] fetch2: validate striplevel parameter

In reply to Yoann Congal

From: Anders Heimer <[email protected]>

The striplevel URL parameter is appended to tar_cmd, which is later run through the shell. Validate it as a decimal count before using it in the tar arguments.

(cherry picked from commit 934fe718bfe29c7ec921e6b598d81ec2ebe8f7c7)

[YC: Removed the striplevel="1\n" subtest case. The URL-decoding regex in decodeurl uses .* without re.DOTALL, causing literal newlines in parameters to be silently truncated during parsing.]

---
 lib/bb/fetch2/__init__.py |  5 ++++-
 lib/bb/tests/fetch.py     | 11 +++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +4 -1
index 2f54cb86e..7f6cf8ba9 100644
@@ -1520,7 +1520,10 @@ class FetchMethod(object):
         if unpack:
             tar_cmd = 'tar --extract --no-same-owner'
             if 'striplevel' in urldata.parm:
-                tar_cmd += ' --strip-components=%s' %  urldata.parm['striplevel']
+                striplevel = urldata.parm['striplevel']
+                if not striplevel.isdigit():
+                    raise UnpackError("Invalid striplevel parameter: %s" % striplevel, urldata.url)
+                tar_cmd += ' --strip-components=%s' % striplevel
             if file.endswith('.tar'):
                 cmd = '%s -f %s' % (tar_cmd, file)
             elif file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'):
lib/bb/tests/fetch.py +11 -0
index 5735cf8f4..37e4eb9f4 100644
@@ -7,6 +7,7 @@
 #
 
 import contextlib
+import shutil
 import unittest
 import hashlib
 import tempfile
@@ -853,6 +854,16 @@ class FetcherLocalTest(FetcherTest):
 
         self.assertIn("does not contain supported data.tar* file", str(context.exception))
 
+    def assertInvalidStriplevel(self, value):
+        with self.assertRaises(bb.fetch2.UnpackError) as context:
+            self.fetchUnpack(['file://archive.tar;subdir=bar;striplevel=%s' % value])
+        self.assertIn("Invalid striplevel parameter", str(context.exception))
+
+    def test_local_striplevel_rejects_invalid_values(self):
+        for value in ("abc", "", "-1", "1 2"):
+            with self.subTest(striplevel=repr(value)):
+                self.assertInvalidStriplevel(value)
+
     def dummyGitTest(self, suffix):
         # Create dummy local Git repo
         src_dir = tempfile.mkdtemp(dir=self.tempdir,
#3 lore raw

[bitbake][scarthgap][2.8][PATCH 3/4] fetch2/git: quote shallow extra ref arguments

In reply to Yoann Congal

From: Anders Heimer <[email protected]>

BB_GIT_SHALLOW_EXTRA_REFS can include wildcard entries. Matching refs advertised by the remote are later passed to git fetch and update-ref while creating shallow tarballs.

Quote the generated command arguments and pass the fetched ref after -- so shell metacharacters and option-like ref names are not interpreted as command syntax or git fetch options.

(cherry picked from commit e9a06f79d9ec767c9d95470be78b006d6fd0d59c)

[YC: Only the quote part of the master patch applies.
The "--" part does not. This part is handled by bin/git-make-shallow which only pass arguments to git rev-list and rev-parse through arrays]

---
 lib/bb/fetch2/git.py  |  2 +-
 lib/bb/tests/fetch.py | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)
lib/bb/fetch2/git.py +1 -1
index a3b1a2ada..d8e31284e 100644
@@ -602,7 +602,7 @@ class Git(FetchMethod):
         shallow_cmd = [self.make_shallow_path, '-s']
         for b in shallow_branches:
             shallow_cmd.append('-r')
-            shallow_cmd.append(b)
+            shallow_cmd.append(shlex.quote(b))
         shallow_cmd.extend(shallow_revisions)
         runfetchcmd(subprocess.list2cmdline(shallow_cmd), d, workdir=dest)
 
lib/bb/tests/fetch.py +30 -0
index 37e4eb9f4..2d95ef87d 100644
@@ -2206,6 +2206,36 @@ class GitShallowTest(FetcherTest):
         self.assertRefs(['master', 'origin/master', 'v1.0'])
         self.assertRevCount(1)
 
+    def test_shallow_extra_refs_wildcard_shell_quoted(self):
+        self.add_empty_file('a')
+        marker = os.path.join(self.tempdir, 'ref-command-marker')
+        ref = 'refs/tags/poc;touch${IFS}%s' % marker
+        self.git(['update-ref', ref, 'HEAD'], cwd=self.srcdir)
+
+        self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
+        self.fetch_shallow()
+
+        self.assertFalse(os.path.exists(marker))
+        self.assertRefs(['master', 'origin/master', ref])
+
+    def test_shallow_extra_refs_wildcard_fetch_options(self):
+        self.add_empty_file('a')
+        marker = os.path.join(self.tempdir, 'ref-option-marker')
+        helper = os.path.join(self.tempdir, 'upload-pack-helper')
+        with open(helper, 'w') as f:
+            f.write('#!/bin/sh\n')
+            f.write('touch "%s"\n' % marker)
+            f.write('exec git-upload-pack "$@"\n')
+        os.chmod(helper, 0o755)
+        ref = 'refs/tags/--upload-pack=%s' % helper
+        self.git(['update-ref', ref, 'HEAD'], cwd=self.srcdir)
+
+        self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
+        self.fetch_shallow()
+
+        self.assertFalse(os.path.exists(marker))
+        self.assertRefs(['master', 'origin/master', ref])
+
     def test_shallow_missing_extra_refs(self):
         self.add_empty_file('a')
         self.add_empty_file('b')
#4 lore raw

[bitbake][scarthgap][2.8][PATCH 1/4] fetch2: validate deb/ipk data member names

In reply to Yoann Congal

From: Anders Heimer <[email protected]>

The deb/ipk unpack path selects a data archive member from 'ar -t' output and then passes that member name to a shell command. Previously, any member beginning with data.tar. was selected.

Only select known deb/ipk data archive member names when datafile is created. Quote the package path used in the shell command as it can come from the local fetch path.

Add local fetcher regression coverage for quoted package filenames, valid compressed data members, and unsupported or unsafe data member names.

(cherry picked from commit 73ae3a2447ec93df39bc66cf3d8f9b2ea1bfe3bf)
---
 lib/bb/fetch2/__init__.py | 10 +++++---
 lib/bb/tests/fetch.py     | 53 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 3 deletions(-)
lib/bb/fetch2/__init__.py +7 -3
index 224408de0..2f54cb86e 100644
@@ -23,6 +23,7 @@ import collections
 import subprocess
 import pickle
 import errno
+import shlex
 import bb.persist_data, bb.utils
 import bb.checksum
 import bb.process
@@ -1567,16 +1568,19 @@ class FetchMethod(object):
             elif file.endswith('.deb') or file.endswith('.ipk'):
                 output = subprocess.check_output(['ar', '-t', file], preexec_fn=subprocess_setup)
                 datafile = None
+                valid_datafiles = ('data.tar', 'data.tar.gz', 'data.tar.xz',
+                                   'data.tar.zst', 'data.tar.bz2', 'data.tar.lzma')
                 if output:
                     for line in output.decode().splitlines():
-                        if line.startswith('data.tar.'):
+                        if line in valid_datafiles:
                             datafile = line
                             break
                     else:
-                        raise UnpackError("Unable to unpack deb/ipk package - does not contain data.tar.* file", urldata.url)
+                        raise UnpackError("Unable to unpack deb/ipk package - does not contain supported data.tar* file", urldata.url)
                 else:
                     raise UnpackError("Unable to unpack deb/ipk package - could not list contents", urldata.url)
-                cmd = 'ar x %s %s && %s -p -f %s && rm %s' % (file, datafile, tar_cmd, datafile, datafile)
+                quoted_datafile = shlex.quote(datafile)
+                cmd = 'ar x %s %s && %s -p -f %s && rm %s' % (shlex.quote(file), quoted_datafile, tar_cmd, quoted_datafile, quoted_datafile)
 
         # If 'subdir' param exists, create a dir and use it as destination for unpack cmd
         if 'subdir' in urldata.parm:
lib/bb/tests/fetch.py +53 -0

71 lines not on this page · raw message