classes/insane: increase shebang size limit
PATCH 1/3 classes/insane: increase shebang size limit
Since Linux 5.1 the shebang buffer has been 256 bytes[1], so update the check to match.
Also rewrite the test, create a variable for the magic number (that has the same name as the kernel #define), don't pointlessly try to decode the bytes as UTF-8, and consolidate the test logic to entirely inside the try block.
[1] linux 6eb3c3d0a52dc ("exec: increase BINPRM_BUF_SIZE to 256")
--- meta/classes-global/insane.bbclass | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
meta/classes-global/insane.bbclass +10 -13
@@ -83,25 +83,22 @@ QAPATHTEST[shebang-size] = "package_qa_check_shebang_size" def package_qa_check_shebang_size(path, name, d, elf): global cpath + # From kernel 5.1 onwards (specifically linux 6eb3c3d0a52dc ("exec: increase + # BINPRM_BUF_SIZE to 256")) the shebang buffer is was increased from 128 bytes + # to 256 bytes. + BINPRM_BUF_SIZE = 256 + if elf or cpath.islink(path) or not cpath.isfile(path): return try: with open(path, 'rb') as f: - stanza = f.readline(130) + stanza = f.readline(BINPRM_BUF_SIZE) + if stanza.startswith(b'#!') and len(stanza) > BINPRM_BUF_SIZE: + oe.qa.handle_error("shebang-size", "%s: %s maximum shebang size exceeded, the maximum size is %d" % (name, package_qa_clean_path(path, d, name), BINPRM_BUF_SIZE), d) + return except IOError: - return - - if stanza.startswith(b'#!'): - try: - stanza.decode("utf-8") - except UnicodeDecodeError: - #If it is not a text file, it is not a script - return - - if len(stanza) > 129: - oe.qa.handle_error("shebang-size", "%s: %s maximum shebang size exceeded, the maximum size is 128." % (name, package_qa_clean_path(path, d, name)), d) - return + pass QAPATHTEST[libexec] = "package_qa_check_libexec" def package_qa_check_libexec(path,name, d, elf):
Signature · 1 line
2.43.0
PATCH 2/3 classes/insane: create one CachedPath instance in qa_check_staged
There's no need to create a new CachedPath instance for every file that we want to scan, just create one at the beginning of the function.
--- meta/classes-global/insane.bbclass | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
meta/classes-global/insane.bbclass +4 -3
@@ -729,6 +729,10 @@ def qa_check_staged(path,d): workdir = os.path.join(tmpdir, "work") recipesysroot = d.getVar("RECIPE_SYSROOT") + # package_qa_check_shebang_size needs the global cpath to be already created + global cpath + cpath = oe.cachedpath.CachedPath() + if bb.data.inherits_class("native", d) or bb.data.inherits_class("cross", d): pkgconfigcheck = workdir else:
@@ -772,10 +776,7 @@ def qa_check_staged(path,d): oe.qa.handle_error("pkgconfig", error_msg, d) if not skip_shebang_size: - global cpath - cpath = oe.cachedpath.CachedPath() package_qa_check_shebang_size(path, "", d, None) - cpath = None # Walk over all files in a directory and call func def package_qa_walk(checkfuncs, package, d):
Signature · 1 line
2.43.0
PATCH 3/3 classes/insane: clean up do_qa_sysroot
In reply to Ross Burtondo_populate_sysroot copies SYSROOT_DIRS into SYSROOT_DESTDIR, so there's no need to loop over SYSROOT_DIRS when checking files: qa_check_staged can just recurse down the entire tree.
--- meta/classes-global/insane.bbclass | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
meta/classes-global/insane.bbclass +1 -3
@@ -1222,9 +1222,7 @@ addtask do_package_qa_setscene python do_qa_sysroot() { bb.note("QA checking do_populate_sysroot") - sysroot_destdir = d.expand('${SYSROOT_DESTDIR}') - for sysroot_dir in d.expand('${SYSROOT_DIRS}').split(): - qa_check_staged(sysroot_destdir + sysroot_dir, d) + qa_check_staged(d.getVar("SYSROOT_DESTDIR"), d) oe.qa.exit_with_message_if_errors("do_populate_sysroot for this recipe installed files with QA issues", d) } do_populate_sysroot[postfuncs] += "do_qa_sysroot"
Signature · 1 line
2.43.0
Ross Burton via lists.openembedded.org schrieb am Di 30. Jun, 15:07 (+0100):
meta/classes-global/insane.bbclass QAPATHTEST[shebang-size] = "package_qa_check_shebang_size" · line 87
Quoted 10 lines
meta/classes-global/insane.bbclass +2
-0@@ -83,25 +83,22 @@ QAPATHTEST[shebang-size] = "package_qa_check_shebang_size" def package_qa_check_shebang_size(path, name, d, elf): global cpath + # From kernel 5.1 onwards (specifically linux 6eb3c3d0a52dc ("exec: increase + # BINPRM_BUF_SIZE to 256")) the shebang buffer is was increased from 128 bytes
The »is« is too much.
Regards, Jörg
Signature · 6 lines
Navimatix GmbH T: 03641 - 327 99 0 Tatzendpromenade 2 F: 03641 - 526 306 07745 Jena www.navimatix.de Geschäftsführer: Steffen Späthe, Jan Rommeley Registergericht: Amtsgericht Jena, HRB 501480
Quoted 10 lines · Ross Burton via lists.openembedded.org
Since Linux 5.1 the shebang buffer has been 256 bytes[1], so update the check to match.
Also rewrite the test, create a variable for the magic number (that has the same name as the kernel #define), don't pointlessly try to decode the bytes as UTF-8, and consolidate the test logic to entirely inside the try block.
[1] linux
6eb3c3d0a52dc("exec: increaseBINPRM_BUF_SIZEto 256")
---
Hi Ross,
Thanks for your patch.
I believe you also need to update the test_sysroot_max_shebang selftest / sysroot-shebang-test-native recipe:
2026-07-01 11:25:35,511 - oe-selftest - INFO - FAIL: sysroot.SysrootTests.test_sysroot_max_shebang (subunit.RemotedTestCase)
2026-07-01 11:25:35,511 - oe-selftest - INFO - ----------------------------------------------------------------------
2026-07-01 11:25:35,511 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last):
File "/srv/pokybuild/yocto-worker/oe-selftest-debian/build/layers/openembedded-core/meta/lib/oeqa/selftest/cases/sysroot.py", line 49, in test_sysroot_max_shebang
self.assertTrue(expected in res.output, msg=res.output)
File "/usr/lib/python3.12/unittest/case.py", line 727, in assertTrue
raise self.failureException(msg)AssertionError: False is not true : NOTE: Reconnecting to bitbake server...
https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/4183
https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/4010
Thanks,
Mathieu
Signature · 3 lines
Mathieu Dubois-Briand, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Hilariously, I was thinking I should write a test case and didn’t even think to check there was one already…
Sorry to break your build, v2 coming soon.
Ross
Quoted 40 lines · Mathieu Dubois-Briand
Quoted 10 lines · Ross Burton via lists.openembedded.org
Since Linux 5.1 the shebang buffer has been 256 bytes[1], so update the check to match.
Also rewrite the test, create a variable for the magic number (that has the same name as the kernel #define), don't pointlessly try to decode the bytes as UTF-8, and consolidate the test logic to entirely inside the try block.
[1] linux
6eb3c3d0a52dc("exec: increaseBINPRM_BUF_SIZEto 256")
---Hi Ross,
Thanks for your patch.
I believe you also need to update the
test_sysroot_max_shebangselftest / sysroot-shebang-test-native recipe:2026-07-01 11:25:35,511 - oe-selftest - INFO - FAIL: sysroot.SysrootTests.test_sysroot_max_shebang (subunit.RemotedTestCase) 2026-07-01 11:25:35,511 - oe-selftest - INFO - ---------------------------------------------------------------------- 2026-07-01 11:25:35,511 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last): File "/srv/pokybuild/yocto-worker/oe-selftest-debian/build/layers/openembedded-core/meta/lib/oeqa/selftest/cases/sysroot.py", line 49, in test_sysroot_max_shebang self.assertTrue(expected in res.output, msg=res.output) File "/usr/lib/python3.12/unittest/case.py", line 727, in assertTrue raise self.failureException(msg)AssertionError: False is not true : NOTE: Reconnecting to bitbake server...
https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/4183
https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/4010Thanks,
MathieuSignature · 3 lines
Mathieu Dubois-Briand, Bootlin Embedded Linux and Kernel engineering https://bootlin.com