Skip to content

Commit d13bd49

Browse files
proc: limit the max length of goroutine's label map (#3928) (#3968)
Co-authored-by: Huang Hongyu <[email protected]>
1 parent 193f21e commit d13bd49

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/proc/variables.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const (
4343
maxMapBucketsFactor = 100 // Maximum numbers of map buckets to read for every requested map entry when loading variables through (*EvalScope).LocalVariables and (*EvalScope).FunctionArguments.
4444

4545
maxGoroutineUserCurrentDepth = 30 // Maximum depth used by (*G).UserCurrent to search its location
46+
47+
maxGoroutinesLabelEntries = 1_000 // Maximum number of label entries for a goroutine's label map
4648
)
4749

4850
type floatSpecial uint8
@@ -585,6 +587,13 @@ func (g *G) Labels() map[string]string {
585587
case reflect.Struct:
586588
labelMap, _ = labelMap.structMember("list")
587589
if labelMap != nil {
590+
// ensure the labelMap.Len is a valid value to prevent infinite loops
591+
if labelMap.Len < 0 {
592+
labelMap.Len = 0
593+
}
594+
if labelMap.Len > maxGoroutinesLabelEntries {
595+
labelMap.Len = maxGoroutinesLabelEntries
596+
}
588597
for i := int64(0); i < labelMap.Len; i++ {
589598
v, err := labelMap.sliceAccess(int(i))
590599
if err != nil {

0 commit comments

Comments
 (0)