streaming

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

commit f06b871300334ace54d1d6c9678156a53cfcff65
parent 8c5823d831ca8c25cf4b0e1119b049acf32e3471
Author: blackfalcon <blackfalcon.ru@gmail.com>
Date:   Tue, 28 May 2024 08:30:22 -0300

m3u8: validate closed captions when parsing

Resolves https://github.com/untangledco/streaming/issues/6

Diffstat:
Mm3u8/parse.go | 14++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/m3u8/parse.go b/m3u8/parse.go @@ -308,13 +308,15 @@ func parseCCInfo(s string) (*CCInfo, error) { if len(s) < 3 { return nil, fmt.Errorf("too short") } - if s[:1] == "CC" { - // TODO(otl): compare against literals '1', '2', '3', '4' instead of parsing. - i, err := strconv.Atoi(string(s[2])) - if err != nil { - return nil, fmt.Errorf("parse channel number: %w", err) + if s[:2] == "CC" { + // MUST have one of the values: "CC1", "CC2", "CC3", "CC4" + switch { + case len(s) == 3 && s[2] >= '1' && s[2] <= '4': + i := int(s[2] - '0') + return &CCInfo{i, false}, nil + default: + return nil, fmt.Errorf("invalid closed caption %s", s) } - return &CCInfo{i, false}, nil } // SERVICE00 if len(s) < 8 {