bazelbuild / bazelbuild/bazel

Builtin functions can be called recursively

Open
#29,920 2 comments 0 reactions 0 assignees View on GitHub
P4 team-Starlark-Interpreter type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

There are 3 builtin functions that take a `key` as a parameter, that the builtin function should invoke. These are `min`, `max` and `sorted`. There is no protection for these functions to call themselves recursively. Eg

```
print(max([[1,2,3], [4,5,6]], key = max))
```

Starlark forbids functions to call themselves recursively, so this should be detected and prevented.

### Which category does this issue belong to?

_No response_

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

print(max([[1,2,3], [4,5,6]], key = max))

### Which operating system are you running Bazel on?

MacOS

### What is the output of `bazel info release`?

release 9.1.1

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text

```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start from the implementations of the min, max, and sorted builtins and reproduce the provided max(..., key=max) example. Trace how their key callbacks are invoked, then add protection against recursive self-calls and regression coverage for all three builtins.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.