Skip to content

Commit 788c979

Browse files
committed
fix(client): guard against int overflow in ClientWithAttachments marshal
CodeQL flagged go/allocation-size-overflow on len(rec)+len(extra) feeding make's capacity. Not exploitable in practice (both come from json.Marshal of bounded structs), but add an explicit MaxInt guard to silence the analyzer and make the precondition obvious.
1 parent 66f946e commit 788c979

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

web/service/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9+
"math"
910
"strings"
1011
"sync"
1112
"time"
@@ -47,6 +48,9 @@ func (c ClientWithAttachments) MarshalJSON() ([]byte, error) {
4748
if len(rec) < 2 || rec[len(rec)-1] != '}' || len(extra) <= 2 {
4849
return rec, nil
4950
}
51+
if len(extra) > math.MaxInt-len(rec) {
52+
return rec, nil
53+
}
5054
out := make([]byte, 0, len(rec)+len(extra))
5155
out = append(out, rec[:len(rec)-1]...)
5256
if len(rec) > 2 {

0 commit comments

Comments
 (0)