Guard recipe-local discovery against configured build directories
Context
PR #538 fixes the unbounded recipe-local traversal reported in #537 by skipping .conf documents, deferring discovery until SRC_URI completion, using one asynchronous fast-glob.stream() traversal, and supporting cancellation.
A follow-up pre-flight confirmed that cancellation is effective, but also showed that recipe-local discovery is not intrinsically protected from a search root that overlaps the configured BitBake build directory.
Pre-flight findings
A synthetic local benchmark containing approximately 40,000 filesystem entries produced the following diagnostic results:
- a targeted search with
maxFileResults: 1still traversed 16,000 matching entries and retained 8,000 directories; - the broad completion search materialized 40,565 entries and increased process RSS by approximately 47 MiB;
- active cancellation stopped traversal promptly.
These measurements are diagnostic and are not proposed as CI timing thresholds.
The current implementation limits the number of file results retained by the targeted document-link path, but it does not stop traversal after that limit is reached. Directory results are not bounded.
The .conf exclusion prevents the exact reproduction from #537, but other document names or layouts could still produce recipe-local roots equal to or located inside the configured build directory.
Proposed behavior
Recipe-local discovery should receive the active BitBake build-folder context and classify each candidate search root before starting traversal.
The active pathToBuildFolder and workingDirectory should be obtained from the current build configuration.
Paths should be resolved relative to the active working directory and canonicalized when possible.
Apply the following policy:
- reject a candidate root equal to the configured build directory;
- reject a candidate root located inside the configured build directory;
- reject symlinked roots that resolve to either of those cases;
- allow roots that are disjoint from the build directory;
- when a candidate root contains the build directory, exclude the build-directory subtree rather than rejecting the entire candidate root.
If a configured or candidate path does not yet exist, use a normalized absolute-path comparison as a fallback to filesystem canonicalization.
Tests
Add deterministic tests covering:
- root equal to the build directory;
- root inside the build directory;
- root disjoint from the build directory;
- root containing the build directory;
- symlink resolving to the build directory;
- relative build-folder paths resolved against the active working directory;
- different build folders selected through build configurations;
- undefined or non-existing build-folder settings;
- no stream creation when every candidate root is rejected;
- build-subtree exclusion when an otherwise valid root contains it.
Non-goals
- changing the existing
.confbehavior from PR #538; - adding wall-clock performance assertions to CI;
- silently truncating completion results;
- changing the
getRecipeLocalFilesclient-server contract; - changing completion caching semantics.
Acceptance criteria
- recipe-local discovery cannot traverse the configured build directory or any of its descendants;
- symlink aliases of the build directory receive the same protection;
- valid recipe-local roots remain functional;
- active build configurations are respected;
- relative settings are handled consistently;
- deterministic regression tests cover the root-classification policy;
- lint, TypeScript compilation, and relevant tests pass.
Relationship to existing work
This is a follow-up hardening task for #537 and PR #538. It does not indicate that the current fix is incomplete and should not block its review or merge.
The build recursion described in #537 was already a particular edge case that few developers encountered. It does not correspond to any standard Yocto workspace practices. I don't think there are other common use cases to implement such protections.
In other cases, there might always be recipe folders containing heaps of data that would take too long to iterate. Not just from a reference to the Yocto build tree, but other huge directories, like an extracted rootfs, or the entire linux kernel sources for instances. A targeted guard against build tree references would not solve these cases.
However, I don't think we need to protect against them at all. We already have the cancellation policy for that. An additional timeout-policy could double on it, but it's just redundant.
Unless someone comes up with a real field issue, I suggest to close this issue for now.
Agreed. The build-tree guard would only address one specific source of large traversals, while the cancellation mechanism already provides the general protection for pathological scans. I will close this for now as not planned; we can revisit it if a concrete field issue shows that cancellation is insufficient.