diff mbox series

checksum: only split file-checksums entries at right-most colon

Message ID 20260513105549.527210-1-ravi@prevas.dk
State New
Headers show
Series checksum: only split file-checksums entries at right-most colon | expand

Commit Message

Rasmus Villemoes May 13, 2026, 10:55 a.m. UTC
While paths generally do not contain :, it is not forbidden. Even when
ordinary files do not contain : anywhere in the path, there is a
real-world example where the current code ends up emitting a false
warning:

meta-rauc's bundle.bbclass [*] expects the user to set RAUC_KEY_FILE
and RAUC_CERT_FILE to point at the key/certificate used for signing a
RAUC bundle. Since those files are not in SRC_URI but are used
directly in the do_bundle task, they set

do_bundle[file-checksums] += "${RAUC_CERT_FILE}:False ${RAUC_KEY_FILE}:False"

The :False is because they also allow these variables to be pkcs#11
uris. However, in that case, it will be something like

  RAUC_KEY_FILE = "pkcs11:object=some-id"

and the file-checksums entry ends up being
"pkcs11:object=some-id:False". So the python code ends up seeing
"object=some-id" as the [1] entry in the split and "pkcs11" as the [0]
entry, and the whole thing ends up doing

WARNING: Unable to get checksum for system-bundle SRC_URI entry pkcs11: [Errno 2] No such file or directory: 'pkcs11'

The code really just wants the right-most, colon-delimited field, with
anything before being the path. So change to use .rsplit(":", 1)
instead. This should make no functional change for items that contain
exactly one :, and matches the change done in a70a7376a ("cache:
correctly handle file names containing colons").

[*] https://github.com/rauc/meta-rauc/blob/master/classes-recipe/bundle.bbclass

Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
---

Note: I'm not really sure meta-rauc's use of [file-checksums] in this
way is correct; it seems that the flag should reflect whether the file
actually exists, not whether it is guaranteed to exist. But
regardless, this patch should be correct.

 lib/bb/checksum.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Richard Purdie May 13, 2026, 11:33 a.m. UTC | #1
On Wed, 2026-05-13 at 12:55 +0200, Rasmus Villemoes wrote:
> While paths generally do not contain :, it is not forbidden. Even when
> ordinary files do not contain : anywhere in the path, there is a
> real-world example where the current code ends up emitting a false
> warning:
> 
> meta-rauc's bundle.bbclass [*] expects the user to set RAUC_KEY_FILE
> and RAUC_CERT_FILE to point at the key/certificate used for signing a
> RAUC bundle. Since those files are not in SRC_URI but are used
> directly in the do_bundle task, they set
> 
> do_bundle[file-checksums] += "${RAUC_CERT_FILE}:False ${RAUC_KEY_FILE}:False"
> 
> The :False is because they also allow these variables to be pkcs#11
> uris. However, in that case, it will be something like
> 
>   RAUC_KEY_FILE = "pkcs11:object=some-id"
> 
> and the file-checksums entry ends up being
> "pkcs11:object=some-id:False". So the python code ends up seeing
> "object=some-id" as the [1] entry in the split and "pkcs11" as the [0]
> entry, and the whole thing ends up doing
> 
> WARNING: Unable to get checksum for system-bundle SRC_URI entry pkcs11: [Errno 2] No such file or directory: 'pkcs11'
> 
> The code really just wants the right-most, colon-delimited field, with
> anything before being the path. So change to use .rsplit(":", 1)
> instead. This should make no functional change for items that contain
> exactly one :, and matches the change done in a70a7376a ("cache:
> correctly handle file names containing colons").
> 
> [*] https://github.com/rauc/meta-rauc/blob/master/classes-recipe/bundle.bbclass
> 
> Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
> ---
> 
> Note: I'm not really sure meta-rauc's use of [file-checksums] in this
> way is correct; it seems that the flag should reflect whether the file
> actually exists, not whether it is guaranteed to exist. But
> regardless, this patch should be correct.

Your patch is probably fine but meta-rauc is not using those correctly,
I suspect it simply won't work or do what they're expecting and the
code is actually pointless in the current form.

Cheers,

Richard
diff mbox series

Patch

diff --git a/lib/bb/checksum.py b/lib/bb/checksum.py
index 3fb39a303..9490199d4 100644
--- a/lib/bb/checksum.py
+++ b/lib/bb/checksum.py
@@ -118,10 +118,10 @@  class FileChecksumCache(MultiProcessCache):
             pth = pth.strip()
             if not pth:
                 continue
-            exist = pth.split(":")[1]
+            exist = pth.rsplit(":", 1)[1]
             if exist == "False":
                 continue
-            pth = pth.split(":")[0]
+            pth = pth.rsplit(":", 1)[0]
             if '*' in pth:
                 # Handle globs
                 for f in glob.glob(pth):