diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cc7a6ddb..f9fca553 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/Makefile b/Makefile index 654d9fc0..34e2ad84 100644 --- a/Makefile +++ b/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" diff --git a/internal/highleveltests/server_test.go b/internal/highleveltests/server_test.go index 59d8573c..af497901 100644 --- a/internal/highleveltests/server_test.go +++ b/internal/highleveltests/server_test.go @@ -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) } diff --git a/pkg/base/response.go b/pkg/base/response.go index db3d20d0..20336495 100644 --- a/pkg/base/response.go +++ b/pkg/base/response.go @@ -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 { diff --git a/pkg/formats/av1.go b/pkg/formats/av1.go index ac11d5b0..e73de756 100644 --- a/pkg/formats/av1.go +++ b/pkg/formats/av1.go @@ -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) } diff --git a/pkg/formats/generic.go b/pkg/formats/generic.go index 66b55e97..2e4a5b52 100644 --- a/pkg/formats/generic.go +++ b/pkg/formats/generic.go @@ -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 } diff --git a/pkg/formats/h264.go b/pkg/formats/h264.go index da8d47c7..9fd78a01 100644 --- a/pkg/formats/h264.go +++ b/pkg/formats/h264.go @@ -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) } diff --git a/pkg/formats/h265.go b/pkg/formats/h265.go index 910a32e8..e3d3a63f 100644 --- a/pkg/formats/h265.go +++ b/pkg/formats/h265.go @@ -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) } diff --git a/pkg/formats/lpcm.go b/pkg/formats/lpcm.go index 5fa3a63c..f342b9e9 100644 --- a/pkg/formats/lpcm.go +++ b/pkg/formats/lpcm.go @@ -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 } diff --git a/pkg/formats/mpeg4_audio_generic.go b/pkg/formats/mpeg4_audio_generic.go index bdd36187..dcc62d1a 100644 --- a/pkg/formats/mpeg4_audio_generic.go +++ b/pkg/formats/mpeg4_audio_generic.go @@ -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) diff --git a/pkg/formats/mpeg4_audio_latm.go b/pkg/formats/mpeg4_audio_latm.go index dd9c28d2..5ddfdc18 100644 --- a/pkg/formats/mpeg4_audio_latm.go +++ b/pkg/formats/mpeg4_audio_latm.go @@ -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 } } diff --git a/pkg/formats/mpeg4_video_es.go b/pkg/formats/mpeg4_video_es.go index bacbf219..f1e65fa6 100644 --- a/pkg/formats/mpeg4_video_es.go +++ b/pkg/formats/mpeg4_video_es.go @@ -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) } diff --git a/pkg/formats/opus.go b/pkg/formats/opus.go index c7c4f67d..0753ca0b 100644 --- a/pkg/formats/opus.go +++ b/pkg/formats/opus.go @@ -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) } diff --git a/pkg/formats/vorbis.go b/pkg/formats/vorbis.go index 6c8a75c0..8287bf68 100644 --- a/pkg/formats/vorbis.go +++ b/pkg/formats/vorbis.go @@ -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 } diff --git a/pkg/formats/vp8.go b/pkg/formats/vp8.go index 8a1e6db1..e83a4260 100644 --- a/pkg/formats/vp8.go +++ b/pkg/formats/vp8.go @@ -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) } diff --git a/pkg/formats/vp9.go b/pkg/formats/vp9.go index a19d31d3..ac085771 100644 --- a/pkg/formats/vp9.go +++ b/pkg/formats/vp9.go @@ -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) } diff --git a/pkg/headers/session.go b/pkg/headers/session.go index 07ef5c18..5a9331a2 100644 --- a/pkg/headers/session.go +++ b/pkg/headers/session.go @@ -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 } diff --git a/pkg/headers/transport.go b/pkg/headers/transport.go index dcbc8ef6..0b47c0a2 100644 --- a/pkg/headers/transport.go +++ b/pkg/headers/transport.go @@ -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 } diff --git a/pkg/media/media.go b/pkg/media/media.go index 10262957..15197d12 100644 --- a/pkg/media/media.go +++ b/pkg/media/media.go @@ -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 } diff --git a/scripts/test.mk b/scripts/test.mk index 569feda5..5325f074 100644 --- a/scripts/test.mk +++ b/scripts/test.mk @@ -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 diff --git a/server.go b/server.go index b206983f..dcdb142d 100644 --- a/server.go +++ b/server.go @@ -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 } diff --git a/server_session.go b/server_session.go index 102ecbfb..a17a1ca4 100644 --- a/server_session.go +++ b/server_session.go @@ -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 }