Skip to content

Commit 97ef623

Browse files
sangwaclaude
andcommitted
fix: guard parseByteSize against uint64-to-int64 overflow
humanize.ParseBytes returns uint64; values above math.MaxInt64 (e.g. "9EiB") would silently wrap to negative on the int64 cast. Now returns a clear error instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 50b3025 commit 97ef623

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

internal/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package app
33
import (
44
"fmt"
55
"log/slog"
6+
"math"
67
"net/url"
78
"path/filepath"
89
"regexp"
@@ -336,6 +337,9 @@ func parseByteSize(s string) (int64, error) {
336337
if err != nil {
337338
return 0, fmt.Errorf("invalid byte size %q: %w", s, err)
338339
}
340+
if n > uint64(math.MaxInt64) {
341+
return 0, fmt.Errorf("byte size %q overflows int64", s)
342+
}
339343
return int64(n), nil
340344
}
341345

internal/endorsements_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ func TestParseByteSize(t *testing.T) {
474474
{"abc", 0, true},
475475
{"-1MiB", 0, true},
476476
{"-5", 0, true},
477+
{"9EiB", 0, true}, // overflows int64
477478
}
478479

479480
for _, tt := range tests {

0 commit comments

Comments
 (0)