From 78081d71d5c8a0b21f750360c1d6cb3cb59c8636 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Sat, 15 Aug 2026 16:27:41 +0200 Subject: [PATCH] rpi: prevent invalid MJPEG sizes (#6080) width and height of MJPEG frames must be multiple of 8 and less than 2048, otherwise they cannot be routed with RTP/RTSP. --- internal/conf/conf_test.go | 18 ++++++++++++++++++ internal/conf/path.go | 12 +++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/internal/conf/conf_test.go b/internal/conf/conf_test.go index fe028cc8..14b7f31f 100644 --- a/internal/conf/conf_test.go +++ b/internal/conf/conf_test.go @@ -414,6 +414,24 @@ func TestConfErrors(t *testing.T) { " source: rpiCamera\n", "'rpiCamera' with same camera ID 0 is used as source in two paths, 'cam1' and 'cam2'", }, + { + "invalid rpi camera mjpeg width", + "paths:\n" + + " cam:\n" + + " source: rpiCamera\n" + + " rpiCameraCodec: mjpeg\n" + + " rpiCameraWidth: 1921\n", + "'rpiCameraWidth' must be a multiple of 8 and less than 2048 when using MJPEG", + }, + { + "invalid rpi camera mjpeg height", + "paths:\n" + + " cam:\n" + + " source: rpiCamera\n" + + " rpiCameraCodec: mjpeg\n" + + " rpiCameraHeight: 2048\n", + "'rpiCameraHeight' must be a multiple of 8 and less than 2048 when using MJPEG", + }, { "invalid srt publish passphrase", "paths:\n" + diff --git a/internal/conf/path.go b/internal/conf/path.go index de5cc4ae..dbbe76bf 100644 --- a/internal/conf/path.go +++ b/internal/conf/path.go @@ -585,7 +585,6 @@ func (pconf *Path) validate( } case pconf.Source == "rpiCamera": - if pconf.RPICameraWidth == 0 { return fmt.Errorf("invalid 'rpiCameraWidth' value") } @@ -594,6 +593,17 @@ func (pconf *Path) validate( return fmt.Errorf("invalid 'rpiCameraHeight' value") } + if pconf.RPICameraCodec == "mjpeg" || + (pconf.RPICameraSecondary && pconf.RPICameraCodec == "auto") { + if pconf.RPICameraWidth >= 2048 || (pconf.RPICameraWidth%8) != 0 { + return fmt.Errorf("'rpiCameraWidth' must be a multiple of 8 and less than 2048 when using MJPEG") + } + + if pconf.RPICameraHeight >= 2048 || (pconf.RPICameraHeight%8) != 0 { + return fmt.Errorf("'rpiCameraHeight' must be a multiple of 8 and less than 2048 when using MJPEG") + } + } + switch pconf.RPICameraExposure { case "normal", "short", "long", "custom": default: