You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If starlarkstruct.Struct is exposed to the starlark environment, and one creates a struct with a circular reference, and causes it to be frozen, then there will be a stack overflow.
A module with this Starlark content should reproduce the issue, but I haven't double-checked that it actually does:
--- a/starlarkstruct/struct.go+++ b/starlarkstruct/struct.go@@ -99,6 +99,7 @@ func FromStringDict(constructor starlark
type Struct struct {
constructor starlark.Value
entries entries // sorted by name
+ frozen bool
}
// Default is the default constructor for structs.
@@ -172,8 +173,11 @@ func (s *Struct) Hash() (uint32, error)
return x, nil
}
func (s *Struct) Freeze() {
- for _, e := range s.entries {- e.value.Freeze()+ if !s.frozen {+ s.frozen = true+ for _, e := range s.entries {+ e.value.Freeze()+ }
}
}
The text was updated successfully, but these errors were encountered:
oprypin
changed the title
starlarkstruct Freeze() can cause a stack overflow if ciircular references are involved
starlarkstruct Freeze() can cause a stack overflow if circular references are involved
Nov 25, 2024
Thanks, that fix is correct. The Freeze function should give better guidance about setting the flag before descending for precisely this reason. Do you want to send a PR?
If
starlarkstruct.Struct
is exposed to the starlark environment, and one creates a struct with a circular reference, and causes it to be frozen, then there will be a stack overflow.A module with this Starlark content should reproduce the issue, but I haven't double-checked that it actually does:
A fix for this issue could be done as follows:
The text was updated successfully, but these errors were encountered: