You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ju...@apache.org on 2026/10/02 15:32:12 UTC
(buildstream) branch jbilleter/checkout created (now 89c3b2f80)
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a change to branch jbilleter/checkout
in repository https://gitbox.apache.org/repos/asf/buildstream.git
at 89c3b2f80 cascache.py: Replace existing files in `checkout` for symlinks
This branch includes the following new commits:
new 79de5cf1c utils.py: Fix `_ensure_real_directory()`
new 96621f345 cascache.py: Validate `Directory` node names in `checkout()`
new c5cd0cbb2 _casbaseddirectory.py: Validate `Directory` node names
new 152b9fce2 cascache.py: Detect duplicate `Directory` node names
new 0b6c28329 _casbaseddirectory.py: Detect duplicate `Directory` node names
new 3716916f3 cascache.py: Ensure that `checkout()` doesn't follow directory symlinks
new 89c3b2f80 cascache.py: Replace existing files in `checkout` for symlinks
The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(buildstream) 04/07: cascache.py: Detect duplicate `Directory` node names
Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a commit to branch jbilleter/checkout
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 152b9fce2b86bb2eb2943a1ec5e59f8234f5b62e
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Oct 2 14:31:34 2026 +0200
cascache.py: Detect duplicate `Directory` node names
The REAPI spec requires that each child in the directory must have a
unique path segment (file name).
---
src/buildstream/_cas/cascache.py | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 3384f0522..9fd5b4649 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -185,8 +185,10 @@ class CASCache:
with open(self.objpath(tree), "rb") as f:
directory.ParseFromString(f.read())
+ names = set()
+
for filenode in directory.files:
- _validate_cas_node_name(filenode.name)
+ _validate_cas_node_name(filenode.name, names)
# regular file, create hardlink
fullpath = os.path.join(dest, filenode.name)
@@ -216,13 +218,13 @@ class CASCache:
os.chmod(fullpath, mode)
for dirnode in directory.directories:
- _validate_cas_node_name(dirnode.name)
+ _validate_cas_node_name(dirnode.name, names)
fullpath = os.path.join(dest, dirnode.name)
self.checkout(fullpath, dirnode.digest, can_link=can_link, _fetch=False)
for symlinknode in directory.symlinks:
# symlink
- _validate_cas_node_name(symlinknode.name)
+ _validate_cas_node_name(symlinknode.name, names)
fullpath = os.path.join(dest, symlinknode.name)
os.symlink(symlinknode.target, fullpath)
@@ -835,9 +837,14 @@ def _grouper(iterable, n):
#
# Args:
# name (str): The name of a CAS Directory entry
+# names (set): The set of names in the directory
#
-def _validate_cas_node_name(name: str):
+def _validate_cas_node_name(name: str, names: Set[str]):
if os.path.basename(name) != name or name in (".", ".."):
raise CASCacheError(
f"Invalid name in a CAS Directory node: '{name}' (every child in the directory must have a path of exactly one segment)"
)
+
+ if name in names:
+ raise CASCacheError(f"Duplicate name in a CAS Directory node: '{name}'")
+ names.add(name)
(buildstream) 06/07: cascache.py: Ensure that `checkout()` doesn't follow directory symlinks
Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a commit to branch jbilleter/checkout
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 3716916f38b2b3489dd6e6b85982b394bd725136
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Oct 2 13:47:45 2026 +0200
cascache.py: Ensure that `checkout()` doesn't follow directory symlinks
`bst artifact checkout` verifies that the destination is empty. However,
`bst artifact checkout --force` allows checkout to a non-empty
directory. Let's not blindly follow pre-existing directory symlinks even
in that case.
---
src/buildstream/_cas/cascache.py | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 9fd5b4649..28f0dc57f 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -220,6 +220,11 @@ class CASCache:
for dirnode in directory.directories:
_validate_cas_node_name(dirnode.name, names)
fullpath = os.path.join(dest, dirnode.name)
+ # If the destination is a regular file, `os.makedirs()` will catch it.
+ # However, it will not raise an error if it's a valid directory symlink,
+ # so check here that we're not unexpectedly following a symlink.
+ if os.path.islink(fullpath):
+ raise CASCacheError(f"Destination already exists and is a symlink, not a directory: {fullpath}")
self.checkout(fullpath, dirnode.digest, can_link=can_link, _fetch=False)
for symlinknode in directory.symlinks:
(buildstream) 02/07: cascache.py: Validate `Directory` node names in `checkout()`
Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a commit to branch jbilleter/checkout
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 96621f3453613d742029f4038cc4eb60d92fe035
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Oct 2 08:51:27 2026 +0200
cascache.py: Validate `Directory` node names in `checkout()`
The REAPI spec requires that every child in the directory must have a
path of exactly one segment. Raise an error if a `Directory` message
violates the spec.
Reported-by: MopMonk-AI <mo...@tophant.com>
---
src/buildstream/_cas/cascache.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 0db18dd4a..3384f0522 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -186,6 +186,8 @@ class CASCache:
directory.ParseFromString(f.read())
for filenode in directory.files:
+ _validate_cas_node_name(filenode.name)
+
# regular file, create hardlink
fullpath = os.path.join(dest, filenode.name)
@@ -214,11 +216,13 @@ class CASCache:
os.chmod(fullpath, mode)
for dirnode in directory.directories:
+ _validate_cas_node_name(dirnode.name)
fullpath = os.path.join(dest, dirnode.name)
self.checkout(fullpath, dirnode.digest, can_link=can_link, _fetch=False)
for symlinknode in directory.symlinks:
# symlink
+ _validate_cas_node_name(symlinknode.name)
fullpath = os.path.join(dest, symlinknode.name)
os.symlink(symlinknode.target, fullpath)
@@ -823,3 +827,17 @@ def _grouper(iterable, n):
except StopIteration:
return
yield itertools.chain([current], itertools.islice(iterable, n - 1))
+
+
+# _validate_cas_node_name():
+#
+# Validates that a CAS Directory entry name is a single path segment.
+#
+# Args:
+# name (str): The name of a CAS Directory entry
+#
+def _validate_cas_node_name(name: str):
+ if os.path.basename(name) != name or name in (".", ".."):
+ raise CASCacheError(
+ f"Invalid name in a CAS Directory node: '{name}' (every child in the directory must have a path of exactly one segment)"
+ )
(buildstream) 03/07: _casbaseddirectory.py: Validate `Directory` node names
Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a commit to branch jbilleter/checkout
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit c5cd0cbb2992e34463e2fa68aa517a412c5048b8
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Oct 2 11:10:14 2026 +0200
_casbaseddirectory.py: Validate `Directory` node names
The REAPI spec requires that every child in the directory must have a
path of exactly one segment. Raise an error if a `Directory` message
violates the spec.
---
src/buildstream/storage/_casbaseddirectory.py | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/buildstream/storage/_casbaseddirectory.py b/src/buildstream/storage/_casbaseddirectory.py
index 084ec0105..5898b80db 100644
--- a/src/buildstream/storage/_casbaseddirectory.py
+++ b/src/buildstream/storage/_casbaseddirectory.py
@@ -654,10 +654,12 @@ class CasBasedDirectory(Directory):
self.__subtree_read_only = prop.value == "true"
for dentry in pb2_directory.directories:
+ _validate_cas_node_name(dentry.name)
self.__index[dentry.name] = _IndexEntry(
self.__cas_cache, dentry.name, FileType.DIRECTORY, digest=dentry.digest
)
for entry in pb2_directory.files:
+ _validate_cas_node_name(entry.name)
mtime: Optional[timestamp_pb2.Timestamp]
if entry.node_properties.HasField("mtime"):
mtime = entry.node_properties.mtime
@@ -673,6 +675,7 @@ class CasBasedDirectory(Directory):
mtime=mtime,
)
for lentry in pb2_directory.symlinks:
+ _validate_cas_node_name(lentry.name)
self.__index[lentry.name] = _IndexEntry(
self.__cas_cache, lentry.name, FileType.SYMLINK, target=lentry.target
)
@@ -908,3 +911,17 @@ class CasBasedDirectory(Directory):
subdir.__add_files_to_result(path_prefix=relative_pathname, result=result)
else:
result.files_written.append(relative_pathname)
+
+
+# _validate_cas_node_name():
+#
+# Validates that a CAS Directory entry name is a single path segment.
+#
+# Args:
+# name (str): The name of a CAS Directory entry
+#
+def _validate_cas_node_name(name: str):
+ if os.path.basename(name) != name or name in (".", ".."):
+ raise DirectoryError(
+ f"Invalid name in a CAS Directory node: '{name}' (every child in the directory must have a path of exactly one segment)"
+ )
(buildstream) 01/07: utils.py: Fix `_ensure_real_directory()`
Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a commit to branch jbilleter/checkout
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 79de5cf1cbf7ca009cd4ec0e81fc3e06282d45f7
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Oct 2 10:30:39 2026 +0200
utils.py: Fix `_ensure_real_directory()`
`os.path.split()` splits the path into a `(head, tail)` pair, not into a
list of all path segments.
Use `pathlib` to iterate over all path segments and also reject absolute
paths.
`_ensure_real_directory()` is only called from `_process_list()`,
though, where it's separately called for each level in the hierarchy.
Due to this, it seems each path segment was already checked and thus,
the previous bug didn't cause any issues.
---
src/buildstream/utils.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py
index 8673813dc..09cb6b2bd 100644
--- a/src/buildstream/utils.py
+++ b/src/buildstream/utils.py
@@ -34,7 +34,7 @@ import tempfile
import threading
import itertools
from contextlib import contextmanager
-from pathlib import Path
+from pathlib import Path, PurePath
from typing import Callable, IO, Iterable, Iterator, Optional, Tuple, Union, Pattern
from google.protobuf import timestamp_pb2
@@ -1064,7 +1064,10 @@ def _copy_directories(srcdir, destdir, target):
#
def _ensure_real_directory(root, path):
destpath = root
- for name in os.path.split(path):
+ purepath = PurePath(path)
+ if purepath.is_absolute():
+ raise UtilError(f"Expected relative path, got absolute path: {path}")
+ for name in purepath.parts:
destpath = os.path.join(destpath, name)
try:
deststat = os.lstat(destpath)
(buildstream) 05/07: _casbaseddirectory.py: Detect duplicate `Directory` node names
Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a commit to branch jbilleter/checkout
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 0b6c28329ba7fd829a64e1e525b5833649182bb4
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Oct 2 14:35:12 2026 +0200
_casbaseddirectory.py: Detect duplicate `Directory` node names
The REAPI spec requires that each child in the directory must have a
unique path segment (file name).
---
src/buildstream/storage/_casbaseddirectory.py | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/buildstream/storage/_casbaseddirectory.py b/src/buildstream/storage/_casbaseddirectory.py
index 5898b80db..ec3375662 100644
--- a/src/buildstream/storage/_casbaseddirectory.py
+++ b/src/buildstream/storage/_casbaseddirectory.py
@@ -653,13 +653,15 @@ class CasBasedDirectory(Directory):
if prop.name == "SubtreeReadOnly":
self.__subtree_read_only = prop.value == "true"
+ names = set()
+
for dentry in pb2_directory.directories:
- _validate_cas_node_name(dentry.name)
+ _validate_cas_node_name(dentry.name, names)
self.__index[dentry.name] = _IndexEntry(
self.__cas_cache, dentry.name, FileType.DIRECTORY, digest=dentry.digest
)
for entry in pb2_directory.files:
- _validate_cas_node_name(entry.name)
+ _validate_cas_node_name(entry.name, names)
mtime: Optional[timestamp_pb2.Timestamp]
if entry.node_properties.HasField("mtime"):
mtime = entry.node_properties.mtime
@@ -675,7 +677,7 @@ class CasBasedDirectory(Directory):
mtime=mtime,
)
for lentry in pb2_directory.symlinks:
- _validate_cas_node_name(lentry.name)
+ _validate_cas_node_name(lentry.name, names)
self.__index[lentry.name] = _IndexEntry(
self.__cas_cache, lentry.name, FileType.SYMLINK, target=lentry.target
)
@@ -919,9 +921,14 @@ class CasBasedDirectory(Directory):
#
# Args:
# name (str): The name of a CAS Directory entry
+# names (set): The set of names in the directory
#
-def _validate_cas_node_name(name: str):
+def _validate_cas_node_name(name: str, names: Set[str]):
if os.path.basename(name) != name or name in (".", ".."):
raise DirectoryError(
f"Invalid name in a CAS Directory node: '{name}' (every child in the directory must have a path of exactly one segment)"
)
+
+ if name in names:
+ raise DirectoryError(f"Duplicate name in a CAS Directory node: '{name}'")
+ names.add(name)
(buildstream) 07/07: cascache.py: Replace existing files in `checkout` for symlinks
Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a commit to branch jbilleter/checkout
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 89c3b2f80c6658177700c6f76e05eef880467a2f
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Oct 2 14:25:16 2026 +0200
cascache.py: Replace existing files in `checkout` for symlinks
`bst artifact checkout --force` intentionally replaces existing files.
The same should apply to symlinks. Without `--force`, it should not be
possible to hit that code path.
---
src/buildstream/_cas/cascache.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 28f0dc57f..7342b9bbc 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -231,7 +231,14 @@ class CASCache:
# symlink
_validate_cas_node_name(symlinknode.name, names)
fullpath = os.path.join(dest, symlinknode.name)
- os.symlink(symlinknode.target, fullpath)
+ try:
+ os.symlink(symlinknode.target, fullpath)
+ except FileExistsError:
+ try:
+ os.unlink(fullpath)
+ except OSError as e:
+ raise CASCacheError(f"Failed to remove destination file '{fullpath}': {e}") from e
+ os.symlink(symlinknode.target, fullpath)
node_properties = directory.node_properties
if node_properties.HasField("mtime"):