Skip to content

Commit

Permalink
limit the length of elements_string
Browse files Browse the repository at this point in the history
  • Loading branch information
kevkevinpal committed Jan 14, 2025
1 parent d09e594 commit 6176a20
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion routes/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func internalServerErrorHandler(next http.Handler) http.Handler {
rr := negroni.NewResponseWriter(w)

var elements_chain strings.Builder
isExceedingLimit := false
trap.AddInterceptor(&trap.Interceptor{
Pre: func(ctx context.Context, f *core.FuncInfo, args core.Object, results core.Object) (interface{}, error) {
index := strings.Index(f.File, "sphinx-tribes")
Expand All @@ -238,7 +239,14 @@ func internalServerErrorHandler(next http.Handler) http.Handler {
trimmed = f.File[index:]
}
//fmt.Printf("%s:%d %s\n", trimmed, f.Line, f.Name)
elements_chain.WriteString(fmt.Sprintf("%s:%d %s,\n", trimmed, f.Line, f.Name))
newContent := fmt.Sprintf("%s:%d %s,\n", trimmed, f.Line, f.Name)
if elements_chain.Len()+len(newContent) <= 512000 {
elements_chain.WriteString(newContent)
} else if isExceedingLimit == false {
// Optionally, you could log or handle this case differently if needed
fmt.Printf("elements_chain length exceeded 500KB, skipping further additions.\n")
isExceedingLimit = true
}

return nil, nil
},
Expand Down

0 comments on commit 6176a20

Please sign in to comment.