From b76a7c9640b85568e8d41aa62ec871c325287c37 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 30 Jan 2026 14:29:04 -0500 Subject: [PATCH] fix: add null checks for y_image before dereferencing in Analyse When analysis_image is set to ANALYSISIMAGE_YCHANNEL but in_frame is not populated (e.g., LocalCamera which captures directly to image), get_y_image() returns nullptr. The code was dereferencing this null pointer in DetectMotion and Blend calls, causing a segfault. Now checks if y_image is valid before use and skips the operation with a debug message if unavailable. Co-Authored-By: Claude Opus 4.5 --- src/zm_monitor.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 29191cadf..ddd63fe74 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -2146,7 +2146,12 @@ bool Monitor::Analyse() { if (analysis_image == ANALYSISIMAGE_YCHANNEL) { Image *y_image = packet->get_y_image(); Debug(1, "Detecting motion on image %d, y_image %p", packet->image_index, y_image); - motion_score += DetectMotion(*y_image, zoneSet); // DetectMotion tests for null y_image + if (y_image) { + motion_score += DetectMotion(*y_image, zoneSet); + } else { + // y_image unavailable (e.g., LocalCamera without in_frame) - skip motion detection + Debug(1, "y_image unavailable, skipping motion detection"); + } } else { Debug(1, "Detecting motion on image %d, image %p", packet->image_index, packet->image); motion_score += DetectMotion(*(packet->image), zoneSet); @@ -2197,7 +2202,11 @@ bool Monitor::Analyse() { if (analysis_image == ANALYSISIMAGE_YCHANNEL) { Debug(1, "Blending from y-channel"); Image *y_image = packet->get_y_image(); - ref_image.Blend(*y_image, ( state==ALARM ? alarm_ref_blend_perc : ref_blend_perc )); + if (y_image) { + ref_image.Blend(*y_image, ( state==ALARM ? alarm_ref_blend_perc : ref_blend_perc )); + } else { + Debug(1, "y_image unavailable, skipping blend"); + } } else if (packet->image) { Debug(1, "Blending full colour image because analysis_image = %d, in_frame=%p and format %d != %d, %d", analysis_image, packet->in_frame.get(),