Skip to content

Commit ef5ac3f

Browse files
authored
eth/filters: enforce topic-limit early on filter criterias (#29535)
This PR adds a limit of 1000 to the "inner" topics in a filter-criteria
1 parent 67422e2 commit ef5ac3f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

eth/filters/api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ var (
4343
// The maximum number of topic criteria allowed, vm.LOG4 - vm.LOG0
4444
const maxTopics = 4
4545

46+
// The maximum number of allowed topics within a topic criteria
47+
const maxSubTopics = 1000
48+
4649
// filter is a helper struct that holds meta information over the filter type
4750
// and associated subscription in the event system.
4851
type filter struct {
@@ -539,6 +542,9 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
539542
return errors.New("invalid addresses in query")
540543
}
541544
}
545+
if len(raw.Topics) > maxTopics {
546+
return errExceedMaxTopics
547+
}
542548

543549
// topics is an array consisting of strings and/or arrays of strings.
544550
// JSON null values are converted to common.Hash{} and ignored by the filter manager.
@@ -559,6 +565,9 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
559565

560566
case []interface{}:
561567
// or case e.g. [null, "topic0", "topic1"]
568+
if len(topic) > maxSubTopics {
569+
return errExceedMaxTopics
570+
}
562571
for _, rawTopic := range topic {
563572
if rawTopic == nil {
564573
// null component, match all

0 commit comments

Comments
 (0)