streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

commit a2109c70b8c1180b4a6b9400e503e37ff4abdda8
parent 18185121cc63011d9f097754c13cdc4cc11fd72b
Author: Oliver Lowe <o@olowe.co>
Date:   Sat,  3 May 2025 13:22:56 +1000

m3u8: test more bad resolutions

We don't necessarily need to make it easier to specify Variant test cases,
we can pick the already easy-to-test bits of Variant to make better.

References: https://github.com/untangledco/streaming/issues/34

Diffstat:
Mm3u8/parse.go | 9++++-----
Mm3u8/parse_test.go | 21+++++++++++++++++++++
2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/m3u8/parse.go b/m3u8/parse.go @@ -134,9 +134,6 @@ func parseVariant(items chan item) (*Variant, error) { v.Codecs = strings.Split(strings.Trim(it.val, `"`), ",") case "RESOLUTION": it = <-items - if it.typ != itemString { - return nil, fmt.Errorf("parse resolution attribute: unexpected %s", it) - } res, err := parseResolution(it.val) if err != nil { return nil, fmt.Errorf("parse resolution: %w", err) @@ -179,7 +176,7 @@ func parseVariant(items chan item) (*Variant, error) { case "CLOSED-CAPTIONS": it = <-items if it.typ != itemString { - return nil, fmt.Errorf("parse closed-captions: unexpcted %s", it) + return nil, fmt.Errorf("parse closed-captions: unexpected %s", it) } v.ClosedCaptions = strings.Trim(it.val, `"`) default: @@ -192,7 +189,6 @@ func parseVariant(items chan item) (*Variant, error) { return &v, nil } } - fmt.Println(v) return &v, nil } @@ -209,6 +205,9 @@ func parseResolution(s string) (res [2]int, err error) { if err != nil { return res, fmt.Errorf("vertical pixels: %v", err) } + if res[0] < 0 || res[1] < 0 { + return res, fmt.Errorf("negative dimensions") + } return res, nil } diff --git a/m3u8/parse_test.go b/m3u8/parse_test.go @@ -150,3 +150,24 @@ func TestParseSequence(t *testing.T) { t.Errorf("want %d, got %d", 91240, plist.Sequence) } } + +func TestResolution(t *testing.T) { + var tests = []struct { + name string + s string + }{ + {"double x", "1280xx720"}, + {"missing x", "1280720"}, + {"missing height", "1280x"}, + {"negative", "-1x-1"}, + {"decimal", "10.69x20"}, + } + + for _, tt := range tests { + _, err := parseResolution(tt.s) + if err == nil { + t.Errorf("parse resolution %q (%s): no error", tt.s, tt.name) + continue + } + } +}