Enforce the output limit on subprocess stdout copies
Foundry Go checks / check (push) Successful in 1m52s
Foundry Go checks / check (pull_request) Successful in 1m28s

This commit is contained in:
2026-11-05 11:36:54 +08:00
parent d80854deae
commit 81c2d2e6df
+4 -4
View File
@@ -20,16 +20,16 @@ const executable = "/opt/codex/node_modules/.bin/codex"
var errOutputLimit = errors.New("Codex output limit exceeded")
type outputBuffer struct {
bytes.Buffer
buffer bytes.Buffer
exceeded bool
}
func (b *outputBuffer) Write(p []byte) (int, error) {
if len(p) > maxOutput-b.Len() {
if len(p) > maxOutput-b.buffer.Len() {
b.exceeded = true
return 0, errOutputLimit
}
return b.Buffer.Write(p)
return b.buffer.Write(p)
}
func ServeWorker(socket string) error {
@@ -97,7 +97,7 @@ func execute(w http.ResponseWriter, r *http.Request, prompt string) {
default:
var result string
var completed bool
for _, line := range bytes.Split(bytes.TrimSpace(output.Bytes()), []byte("\n")) {
for _, line := range bytes.Split(bytes.TrimSpace(output.buffer.Bytes()), []byte("\n")) {
var event struct {
Type string `json:"type"`
Item struct {