File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 1
- // Copyright 2023 Blink Labs Software
1
+ // Copyright 2025 Blink Labs Software
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
15
15
package muxer
16
16
17
17
import (
18
+ "math"
18
19
"time"
19
20
)
20
21
@@ -45,14 +46,21 @@ type Segment struct {
45
46
// NewSegment returns a new Segment given a protocol ID, payload bytes, and whether the segment
46
47
// is a response
47
48
func NewSegment (protocolId uint16 , payload []byte , isResponse bool ) * Segment {
49
+ // time since unix epoch even as nanoseconds will not overflow soon
50
+ // #nosec G115
48
51
header := SegmentHeader {
49
52
Timestamp : uint32 (time .Now ().UnixNano () & 0xffffffff ),
50
53
ProtocolId : protocolId ,
51
54
}
52
55
if isResponse {
53
56
header .ProtocolId = header .ProtocolId + segmentProtocolIdResponseFlag
54
57
}
55
- header .PayloadLength = uint16 (len (payload ))
58
+ size := len (payload )
59
+ if size > SegmentMaxPayloadLength || size > math .MaxUint16 {
60
+ return nil
61
+ }
62
+ // payload size fits within length
63
+ header .PayloadLength = uint16 (size )
56
64
segment := & Segment {
57
65
SegmentHeader : header ,
58
66
Payload : payload ,
You can’t perform that action at this time.
0 commit comments