Skip to content

Commit 2c3a48d

Browse files
committed
improve NALU size limit errors
1 parent 20b6d71 commit 2c3a48d

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

pkg/format/rtpav1/decoder.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,12 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, error) {
140140
l := len(obus)
141141

142142
if (d.frameBufferLen + l) > av1.MaxOBUsPerTemporalUnit {
143+
errCount := d.frameBufferLen + l
143144
d.frameBuffer = nil
144145
d.frameBufferLen = 0
145146
d.frameBufferSize = 0
146-
return nil, fmt.Errorf("OBU count exceeds maximum allowed (%d)",
147-
av1.MaxOBUsPerTemporalUnit)
147+
return nil, fmt.Errorf("OBU count (%d) exceeds maximum allowed (%d)",
148+
errCount, av1.MaxOBUsPerTemporalUnit)
148149
}
149150

150151
addSize := 0

pkg/format/rtpav1/decoder_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestDecoderErrorLimit(t *testing.T) {
5252
})
5353
}
5454

55-
require.EqualError(t, err, "OBU count exceeds maximum allowed (10)")
55+
require.EqualError(t, err, "OBU count (11) exceeds maximum allowed (10)")
5656
}
5757

5858
func TestDecodeErrorMissingPacket(t *testing.T) {

pkg/format/rtph264/decoder.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,12 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, error) {
213213
l := len(nalus)
214214

215215
if (d.frameBufferLen + l) > h264.MaxNALUsPerAccessUnit {
216+
errCount := d.frameBufferLen + l
216217
d.frameBuffer = nil
217218
d.frameBufferLen = 0
218219
d.frameBufferSize = 0
219-
return nil, fmt.Errorf("NALU count exceeds maximum allowed (%d)",
220-
h264.MaxNALUsPerAccessUnit)
220+
return nil, fmt.Errorf("NALU count (%d) exceeds maximum allowed (%d)",
221+
errCount, h264.MaxNALUsPerAccessUnit)
221222
}
222223

223224
addSize := 0

pkg/format/rtph264/decoder_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func TestDecoderErrorLimit(t *testing.T) {
241241
})
242242
}
243243

244-
require.EqualError(t, err, "NALU count exceeds maximum allowed (25)")
244+
require.EqualError(t, err, "NALU count (26) exceeds maximum allowed (25)")
245245
}
246246

247247
func TestDecodeErrorMissingPacket(t *testing.T) {

pkg/format/rtph265/decoder.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, error) {
172172
l := len(nalus)
173173

174174
if (d.frameBufferLen + l) > h265.MaxNALUsPerAccessUnit {
175+
errCount := d.frameBufferLen + l
175176
d.frameBuffer = nil
176177
d.frameBufferLen = 0
177178
d.frameBufferSize = 0
178-
return nil, fmt.Errorf("NALU count exceeds maximum allowed (%d)",
179-
h265.MaxNALUsPerAccessUnit)
179+
return nil, fmt.Errorf("NALU count (%d) exceeds maximum allowed (%d)",
180+
errCount, h265.MaxNALUsPerAccessUnit)
180181
}
181182

182183
addSize := 0

pkg/format/rtph265/decoder_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestDecoderErrorLimit(t *testing.T) {
5858
})
5959
}
6060

61-
require.EqualError(t, err, "NALU count exceeds maximum allowed (21)")
61+
require.EqualError(t, err, "NALU count (22) exceeds maximum allowed (21)")
6262
}
6363

6464
func TestDecodeErrorMissingPacket(t *testing.T) {

0 commit comments

Comments
 (0)