mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
add 32-bit tests; return errors in case of string-to-int overflows (#276)
This commit is contained in:
8
.github/workflows/test.yml
vendored
8
.github/workflows/test.yml
vendored
@@ -40,3 +40,11 @@ jobs:
|
||||
go-version: "1.20"
|
||||
|
||||
- run: make test-highlevel-nodocker
|
||||
|
||||
test32:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- run: make test32
|
||||
|
1
Makefile
1
Makefile
@@ -11,6 +11,7 @@ help:
|
||||
@echo " mod-tidy run go mod tidy"
|
||||
@echo " format format source files"
|
||||
@echo " test run tests"
|
||||
@echo " test32 run tests on a 32-bit system"
|
||||
@echo " test-highlevel run high-level tests"
|
||||
@echo " lint run linter"
|
||||
@echo " bench run benchmarks"
|
||||
|
@@ -215,7 +215,7 @@ func (c *container) wait() int {
|
||||
exec.Command("docker", "wait", "gortsplib-test-"+c.name).Run()
|
||||
out, _ := exec.Command("docker", "inspect", "gortsplib-test-"+c.name,
|
||||
"--format={{.State.ExitCode}}").Output()
|
||||
code, _ := strconv.ParseInt(string(out[:len(out)-1]), 10, 64)
|
||||
code, _ := strconv.ParseInt(string(out[:len(out)-1]), 10, 32)
|
||||
return int(code)
|
||||
}
|
||||
|
||||
|
@@ -150,11 +150,11 @@ func (res *Response) Unmarshal(br *bufio.Reader) error {
|
||||
}
|
||||
statusCodeStr := string(byts[:len(byts)-1])
|
||||
|
||||
statusCode64, err := strconv.ParseInt(statusCodeStr, 10, 32)
|
||||
tmp, err := strconv.ParseUint(statusCodeStr, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse status code")
|
||||
}
|
||||
res.StatusCode = StatusCode(statusCode64)
|
||||
res.StatusCode = StatusCode(tmp)
|
||||
|
||||
byts, err = readBytesLimited(br, '\r', 255)
|
||||
if err != nil {
|
||||
|
@@ -24,7 +24,7 @@ func (f *AV1) unmarshal(payloadType uint8, clock string, codec string, rtpmap st
|
||||
for key, val := range fmtp {
|
||||
switch key {
|
||||
case "level-idx":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid level-idx: %v", val)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func (f *AV1) unmarshal(payloadType uint8, clock string, codec string, rtpmap st
|
||||
f.LevelIdx = &v2
|
||||
|
||||
case "profile":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid profile: %v", val)
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (f *AV1) unmarshal(payloadType uint8, clock string, codec string, rtpmap st
|
||||
f.Profile = &v2
|
||||
|
||||
case "tier":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid tier: %v", val)
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ func findClockRate(payloadType uint8, rtpMap string) (int, error) {
|
||||
return 0, fmt.Errorf("invalid rtpmap (%v)", rtpMap)
|
||||
}
|
||||
|
||||
v, err := strconv.ParseInt(tmp[1], 10, 64)
|
||||
v, err := strconv.ParseUint(tmp[1], 10, 31)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@@ -104,7 +104,7 @@ func (f *H264) unmarshal(payloadType uint8, clock string, codec string, rtpmap s
|
||||
}
|
||||
|
||||
case "packetization-mode":
|
||||
tmp, err := strconv.ParseInt(val, 10, 64)
|
||||
tmp, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid packetization-mode (%v)", val)
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ func (f *H265) unmarshal(payloadType uint8, clock string, codec string, rtpmap s
|
||||
}
|
||||
|
||||
case "sprop-max-don-diff":
|
||||
tmp, err := strconv.ParseInt(val, 10, 64)
|
||||
tmp, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid sprop-max-don-diff (%v)", fmtp)
|
||||
}
|
||||
|
@@ -34,14 +34,14 @@ func (f *LPCM) unmarshal(payloadType uint8, clock string, codec string, rtpmap s
|
||||
|
||||
tmp := strings.SplitN(clock, "/", 2)
|
||||
|
||||
tmp1, err := strconv.ParseInt(tmp[0], 10, 64)
|
||||
tmp1, err := strconv.ParseUint(tmp[0], 10, 31)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.SampleRate = int(tmp1)
|
||||
|
||||
if len(tmp) >= 2 {
|
||||
tmp1, err := strconv.ParseInt(tmp[1], 10, 64)
|
||||
tmp1, err := strconv.ParseUint(tmp[1], 10, 31)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ func (f *MPEG4AudioGeneric) unmarshal(
|
||||
}
|
||||
|
||||
case "profile-level-id":
|
||||
tmp, err := strconv.ParseInt(val, 10, 64)
|
||||
tmp, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid profile-level-id: %v", val)
|
||||
}
|
||||
@@ -65,22 +65,22 @@ func (f *MPEG4AudioGeneric) unmarshal(
|
||||
}
|
||||
|
||||
case "sizelength":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
if err != nil {
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil || n > 100 {
|
||||
return fmt.Errorf("invalid AAC SizeLength: %v", val)
|
||||
}
|
||||
f.SizeLength = int(n)
|
||||
|
||||
case "indexlength":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
if err != nil {
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil || n > 100 {
|
||||
return fmt.Errorf("invalid AAC IndexLength: %v", val)
|
||||
}
|
||||
f.IndexLength = int(n)
|
||||
|
||||
case "indexdeltalength":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
if err != nil {
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil || n > 100 {
|
||||
return fmt.Errorf("invalid AAC IndexDeltaLength: %v", val)
|
||||
}
|
||||
f.IndexDeltaLength = int(n)
|
||||
|
@@ -30,7 +30,7 @@ func (f *MPEG4AudioLATM) unmarshal(
|
||||
for key, val := range fmtp {
|
||||
switch key {
|
||||
case "profile-level-id":
|
||||
tmp, err := strconv.ParseInt(val, 10, 64)
|
||||
tmp, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid profile-level-id: %v", val)
|
||||
}
|
||||
@@ -38,7 +38,7 @@ func (f *MPEG4AudioLATM) unmarshal(
|
||||
f.ProfileLevelID = int(tmp)
|
||||
|
||||
case "bitrate":
|
||||
tmp, err := strconv.ParseInt(val, 10, 64)
|
||||
tmp, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid bitrate: %v", val)
|
||||
}
|
||||
@@ -47,12 +47,7 @@ func (f *MPEG4AudioLATM) unmarshal(
|
||||
f.Bitrate = &v
|
||||
|
||||
case "cpresent":
|
||||
tmp, err := strconv.ParseInt(val, 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid cpresent: %v", val)
|
||||
}
|
||||
|
||||
v := (tmp == 1)
|
||||
v := (val == "1")
|
||||
f.CPresent = &v
|
||||
|
||||
case "config":
|
||||
@@ -68,12 +63,7 @@ func (f *MPEG4AudioLATM) unmarshal(
|
||||
}
|
||||
|
||||
case "sbr-enabled":
|
||||
tmp, err := strconv.ParseInt(val, 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid SBR-enabled: %v", val)
|
||||
}
|
||||
|
||||
v := (tmp == 1)
|
||||
v := (val == "1")
|
||||
f.SBREnabled = &v
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ func (f *MPEG4VideoES) unmarshal(
|
||||
for key, val := range fmtp {
|
||||
switch key {
|
||||
case "profile-level-id":
|
||||
tmp, err := strconv.ParseInt(val, 10, 64)
|
||||
tmp, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid profile-level-id: %v", val)
|
||||
}
|
||||
|
@@ -25,12 +25,12 @@ func (f *Opus) unmarshal(payloadType uint8, clock string, codec string, rtpmap s
|
||||
return fmt.Errorf("invalid clock (%v)", clock)
|
||||
}
|
||||
|
||||
sampleRate, err := strconv.ParseInt(tmp[0], 10, 64)
|
||||
sampleRate, err := strconv.ParseUint(tmp[0], 10, 31)
|
||||
if err != nil || sampleRate != 48000 {
|
||||
return fmt.Errorf("invalid sample rate: %d", sampleRate)
|
||||
}
|
||||
|
||||
channelCount, err := strconv.ParseInt(tmp[1], 10, 64)
|
||||
channelCount, err := strconv.ParseUint(tmp[1], 10, 31)
|
||||
if err != nil || channelCount != 2 {
|
||||
return fmt.Errorf("invalid channel count: %d", channelCount)
|
||||
}
|
||||
|
@@ -26,13 +26,13 @@ func (f *Vorbis) unmarshal(payloadType uint8, clock string, codec string, rtpmap
|
||||
return fmt.Errorf("invalid clock (%v)", clock)
|
||||
}
|
||||
|
||||
sampleRate, err := strconv.ParseInt(tmp[0], 10, 64)
|
||||
sampleRate, err := strconv.ParseUint(tmp[0], 10, 31)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.SampleRate = int(sampleRate)
|
||||
|
||||
channelCount, err := strconv.ParseInt(tmp[1], 10, 64)
|
||||
channelCount, err := strconv.ParseUint(tmp[1], 10, 31)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ func (f *VP8) unmarshal(payloadType uint8, clock string, codec string, rtpmap st
|
||||
for key, val := range fmtp {
|
||||
switch key {
|
||||
case "max-fr":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid max-fr: %v", val)
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func (f *VP8) unmarshal(payloadType uint8, clock string, codec string, rtpmap st
|
||||
f.MaxFR = &v2
|
||||
|
||||
case "max-fs":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid max-fs: %v", val)
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ func (f *VP9) unmarshal(payloadType uint8, clock string, codec string, rtpmap st
|
||||
for key, val := range fmtp {
|
||||
switch key {
|
||||
case "max-fr":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid max-fr: %v", val)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func (f *VP9) unmarshal(payloadType uint8, clock string, codec string, rtpmap st
|
||||
f.MaxFR = &v2
|
||||
|
||||
case "max-fs":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid max-fs: %v", val)
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (f *VP9) unmarshal(payloadType uint8, clock string, codec string, rtpmap st
|
||||
f.MaxFS = &v2
|
||||
|
||||
case "profile-id":
|
||||
n, err := strconv.ParseUint(val, 10, 64)
|
||||
n, err := strconv.ParseUint(val, 10, 31)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid profile-id: %v", val)
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ func (h *Session) Unmarshal(v base.HeaderValue) error {
|
||||
|
||||
for k, v := range kvs {
|
||||
if k == "timeout" {
|
||||
iv, err := strconv.ParseUint(v, 10, 64)
|
||||
iv, err := strconv.ParseUint(v, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -13,12 +13,12 @@ import (
|
||||
func parsePorts(val string) (*[2]int, error) {
|
||||
ports := strings.Split(val, "-")
|
||||
if len(ports) == 2 {
|
||||
port1, err := strconv.ParseInt(ports[0], 10, 64)
|
||||
port1, err := strconv.ParseUint(ports[0], 10, 31)
|
||||
if err != nil {
|
||||
return &[2]int{0, 0}, fmt.Errorf("invalid ports (%v)", val)
|
||||
}
|
||||
|
||||
port2, err := strconv.ParseInt(ports[1], 10, 64)
|
||||
port2, err := strconv.ParseUint(ports[1], 10, 31)
|
||||
if err != nil {
|
||||
return &[2]int{0, 0}, fmt.Errorf("invalid ports (%v)", val)
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func parsePorts(val string) (*[2]int, error) {
|
||||
}
|
||||
|
||||
if len(ports) == 1 {
|
||||
port1, err := strconv.ParseInt(ports[0], 10, 64)
|
||||
port1, err := strconv.ParseUint(ports[0], 10, 31)
|
||||
if err != nil {
|
||||
return &[2]int{0, 0}, fmt.Errorf("invalid ports (%v)", val)
|
||||
}
|
||||
@@ -175,7 +175,7 @@ func (h *Transport) Unmarshal(v base.HeaderValue) error {
|
||||
h.InterleavedIDs = ports
|
||||
|
||||
case "ttl":
|
||||
tmp, err := strconv.ParseUint(v, 10, 64)
|
||||
tmp, err := strconv.ParseUint(v, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ func getFormatAttribute(attributes []psdp.Attribute, payloadType uint8, key stri
|
||||
if attr.Key == key {
|
||||
v := strings.TrimSpace(attr.Value)
|
||||
if parts := strings.SplitN(v, " ", 2); len(parts) == 2 {
|
||||
if tmp, err := strconv.ParseInt(parts[0], 10, 8); err == nil && uint8(tmp) == payloadType {
|
||||
if tmp, err := strconv.ParseUint(parts[0], 10, 8); err == nil && uint8(tmp) == payloadType {
|
||||
return parts[1]
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func (m *Media) unmarshal(md *psdp.MediaDescription) error {
|
||||
}
|
||||
}
|
||||
|
||||
tmp, err := strconv.ParseInt(payloadType, 10, 8)
|
||||
tmp, err := strconv.ParseUint(payloadType, 10, 8)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -1,16 +1,22 @@
|
||||
LBITS := $(shell getconf LONG_BIT)
|
||||
ifeq ($(LBITS),64)
|
||||
RACE=-race
|
||||
endif
|
||||
|
||||
test-examples:
|
||||
go build -o /dev/null ./examples/...
|
||||
|
||||
test-pkg:
|
||||
go test -v -race -coverprofile=coverage-pkg.txt ./pkg/...
|
||||
go test -v $(RACE) -coverprofile=coverage-pkg.txt ./pkg/...
|
||||
|
||||
test-root:
|
||||
go test -v -race -coverprofile=coverage-root.txt .
|
||||
go test -v $(RACE) -coverprofile=coverage-root.txt .
|
||||
|
||||
test-nodocker: test-examples test-pkg test-root
|
||||
|
||||
define DOCKERFILE_TEST
|
||||
FROM $(BASE_IMAGE)
|
||||
ARG ARCH
|
||||
FROM $$ARCH/$(BASE_IMAGE)
|
||||
RUN apk add --no-cache make git gcc musl-dev pkgconfig ffmpeg-dev
|
||||
WORKDIR /s
|
||||
COPY go.mod go.sum ./
|
||||
@@ -20,8 +26,15 @@ endef
|
||||
export DOCKERFILE_TEST
|
||||
|
||||
test:
|
||||
echo "$$DOCKERFILE_TEST" | docker build -q . -f - -t temp
|
||||
echo "$$DOCKERFILE_TEST" | docker build -q . -f - -t temp --build-arg ARCH=amd64
|
||||
docker run --rm -it \
|
||||
--name temp \
|
||||
temp \
|
||||
make test-nodocker
|
||||
|
||||
test32:
|
||||
echo "$$DOCKERFILE_TEST" | docker build -q . -f - -t temp --build-arg ARCH=i386
|
||||
docker run --rm \
|
||||
--name temp \
|
||||
temp \
|
||||
make test-nodocker
|
||||
|
@@ -21,7 +21,7 @@ func extractPort(address string) (int, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
tmp2, err := strconv.ParseInt(tmp, 10, 64)
|
||||
tmp2, err := strconv.ParseUint(tmp, 10, 16)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ func findMediaByTrackID(st *ServerStream, trackID string) *media.Media {
|
||||
return st.medias[0]
|
||||
}
|
||||
|
||||
tmp, err := strconv.ParseInt(trackID, 10, 64)
|
||||
tmp, err := strconv.ParseUint(trackID, 10, 31)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user