From 235444ea7c1adfceccf8cdbca5f8496065a4f924 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Thu, 1 Aug 2024 13:22:25 +0200 Subject: [PATCH] h265: fix panic when marshaling SPS --- pkg/codecs/h265/sps.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/codecs/h265/sps.go b/pkg/codecs/h265/sps.go index 383f5c9..006fcd9 100644 --- a/pkg/codecs/h265/sps.go +++ b/pkg/codecs/h265/sps.go @@ -741,6 +741,11 @@ func (s *SPS) Unmarshal(buf []byte) error { return err } + // this prevents a panic in Marshal() + if s.ChromaFormatIdc > 3 { + return fmt.Errorf("invalid chroma_format_idc") + } + if s.ChromaFormatIdc == 3 { s.SeparateColourPlaneFlag, err = bits.ReadFlag(buf, &pos) if err != nil {