mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
fix(plugins): use size cap instead of wraparound check for CodeQL overflow warning
Check individual slice sizes against a 128 MiB cap before the addition, so CodeQL can statically verify the sum cannot overflow.
This commit is contained in:
parent
fc113d1dc6
commit
6c260db60c
@ -130,11 +130,11 @@ func callPluginFunctionRaw[I any, O any](
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("failed to marshal input: %w", err)
|
||||
}
|
||||
totalSize := 4 + len(jsonBytes) + len(rawInputBytes)
|
||||
if totalSize < len(jsonBytes) || totalSize < len(rawInputBytes) {
|
||||
const maxFrameSize = 2 << 20 // 2 MiB
|
||||
if len(jsonBytes) > maxFrameSize || len(rawInputBytes) > maxFrameSize {
|
||||
return result, fmt.Errorf("input frame too large")
|
||||
}
|
||||
frame := make([]byte, totalSize)
|
||||
frame := make([]byte, 4+len(jsonBytes)+len(rawInputBytes))
|
||||
binary.BigEndian.PutUint32(frame[:4], uint32(len(jsonBytes)))
|
||||
copy(frame[4:4+len(jsonBytes)], jsonBytes)
|
||||
copy(frame[4+len(jsonBytes):], rawInputBytes)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user