Prevent HTTP artifact limit overflow

This commit is contained in:
2026-11-19 15:19:39 +00:00
parent 6562d63a02
commit 3105f4d62f
3 changed files with 21 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"math"
"mime"
"os"
"path/filepath"
@@ -136,7 +137,11 @@ func readArtifactFile(path string, maxBytes int64) (*promptkit.Artifact, error)
var reader io.Reader = file
if maxBytes > 0 {
reader = io.LimitReader(file, maxBytes+1)
readLimit := maxBytes
if readLimit < math.MaxInt64 {
readLimit++ // Read one extra byte to detect an oversized file.
}
reader = io.LimitReader(file, readLimit)
}
body, err := io.ReadAll(reader)
if err != nil {