Enforce the output limit on subprocess stdout copies
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user