Skip to content

Commit 603b7c3

Browse files
asayyahJoTurk
authored andcommitted
Fix gosec slice bounds warnings
Add nolint directives for safe slice accesses where bounds are guaranteed by fixed-size allocation or loop conditions.
1 parent 99b388f commit 603b7c3

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

header.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ func (h Header) Marshal() ([]byte, error) {
111111
if h.Count > 31 {
112112
return nil, errInvalidHeader
113113
}
114-
rawPacket[0] |= h.Count << countShift
114+
rawPacket[0] |= h.Count << countShift //nolint:gosec // rawPacket is created with length headerLength (4)
115115

116-
rawPacket[1] = uint8(h.Type)
116+
rawPacket[1] = uint8(h.Type) //nolint:gosec // rawPacket is created with length headerLength (4)
117117

118118
binary.BigEndian.PutUint16(rawPacket[2:], h.Length)
119119

receiver_estimated_maximum_bitrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (p *ReceiverEstimatedMaximumBitrate) String() string {
276276
powers++
277277
}
278278

279-
unit := bitUnits[powers]
279+
unit := bitUnits[powers] //nolint:gosec // powers is bounded by loop condition
280280

281281
return fmt.Sprintf("ReceiverEstimatedMaximumBitrate %x %.2f %s/s", p.SenderSSRC, bitrate, unit)
282282
}

reception_report.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func (r ReceptionReport) Marshal() ([]byte, error) {
7878
return nil, errInvalidTotalLost
7979
}
8080
tlBytes := rawPacket[totalLostOffset:]
81-
tlBytes[0] = byte(r.TotalLost >> 16)
82-
tlBytes[1] = byte(r.TotalLost >> 8)
83-
tlBytes[2] = byte(r.TotalLost)
81+
tlBytes[0] = byte(r.TotalLost >> 16) //nolint:gosec // rawPacket is created with length receptionReportLength (24)
82+
tlBytes[1] = byte(r.TotalLost >> 8) //nolint:gosec // rawPacket is created with length receptionReportLength (24)
83+
tlBytes[2] = byte(r.TotalLost) //nolint:gosec // rawPacket is created with length receptionReportLength (24)
8484

8585
binary.BigEndian.PutUint32(rawPacket[lastSeqOffset:], r.LastSequenceNumber)
8686
binary.BigEndian.PutUint32(rawPacket[jitterOffset:], r.Jitter)

source_description.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ func (s SourceDescriptionItem) Marshal() ([]byte, error) {
313313

314314
rawPacket := make([]byte, sdesTypeLen+sdesOctetCountLen)
315315

316-
rawPacket[sdesTypeOffset] = uint8(s.Type)
316+
rawPacket[sdesTypeOffset] = uint8(s.Type) //nolint:gosec // rawPacket is created with length 2
317317

318318
txtBytes := []byte(s.Text)
319319
octetCount := len(txtBytes)
320320
if octetCount > sdesMaxOctetCount {
321321
return nil, errSDESTextTooLong
322322
}
323-
rawPacket[sdesOctetCountOffset] = uint8(octetCount)
323+
rawPacket[sdesOctetCountOffset] = uint8(octetCount) //nolint:gosec // rawPacket is created with length 2
324324

325325
rawPacket = append(rawPacket, txtBytes...) //nolint:makezero
326326

transport_layer_cc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func (r RecvDelta) Marshal() ([]byte, error) {
270270
// small delta
271271
if r.Type == TypeTCCPacketReceivedSmallDelta && delta >= 0 && delta <= math.MaxUint8 {
272272
deltaChunk := make([]byte, 1)
273-
deltaChunk[0] = byte(delta)
273+
deltaChunk[0] = byte(delta) //nolint:gosec // deltaChunk is created with length 1
274274

275275
return deltaChunk, nil
276276
}

0 commit comments

Comments
 (0)