From 05b8b0319c96e326360b13b039b00693f6bf2d23 Mon Sep 17 00:00:00 2001 From: sladro Date: Mon, 5 Jan 2026 18:00:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/alarm/actions/clip_action.cpp | 14 ++++++++++---- plugins/alarm/actions/snapshot_action.cpp | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/plugins/alarm/actions/clip_action.cpp b/plugins/alarm/actions/clip_action.cpp index b80db3e..90cabac 100644 --- a/plugins/alarm/actions/clip_action.cpp +++ b/plugins/alarm/actions/clip_action.cpp @@ -120,13 +120,17 @@ bool FillYuv420pFromFrame(const Frame& src, int width, int height, AVFrame* dst) if (!s) return false; const int s_stride = PlaneStride(src, 0, width * 3); + const int uv_w = width / 2; + const int uv_h = height / 2; + for (int row = 0; row < height; row += 2) { const uint8_t* row0 = s + row * s_stride; const uint8_t* row1 = (row + 1 < height) ? (s + (row + 1) * s_stride) : row0; uint8_t* y0 = y + row * y_stride; uint8_t* y1 = (row + 1 < height) ? (y + (row + 1) * y_stride) : y0; - uint8_t* uu = u + (row / 2) * u_stride; - uint8_t* vv = v + (row / 2) * v_stride; + const int uv_row = row / 2; + uint8_t* uu = (uv_row < uv_h) ? (u + uv_row * u_stride) : nullptr; + uint8_t* vv = (uv_row < uv_h) ? (v + uv_row * v_stride) : nullptr; for (int col = 0; col < width; col += 2) { int u_sum = 0; @@ -163,8 +167,10 @@ bool FillYuv420pFromFrame(const Frame& src, int width, int height, AVFrame* dst) const int u_val = ((u_sum / denom) + 128 * 256 + 128) >> 8; const int v_val = ((v_sum / denom) + 128 * 256 + 128) >> 8; const int uv_col = col / 2; - uu[uv_col] = ClipU8(u_val); - vv[uv_col] = ClipU8(v_val); + if (uu && vv && uv_col >= 0 && uv_col < uv_w) { + uu[uv_col] = ClipU8(u_val); + vv[uv_col] = ClipU8(v_val); + } } } return true; diff --git a/plugins/alarm/actions/snapshot_action.cpp b/plugins/alarm/actions/snapshot_action.cpp index 11f4639..59b46c5 100644 --- a/plugins/alarm/actions/snapshot_action.cpp +++ b/plugins/alarm/actions/snapshot_action.cpp @@ -118,13 +118,17 @@ bool FillYuv420pFromFrame(const Frame& src, AVFrame* dst) { if (!s) return false; const int s_stride = PlaneStride(src, 0, w * 3); + const int uv_w = w / 2; + const int uv_h = h / 2; + for (int row = 0; row < h; row += 2) { const uint8_t* row0 = s + row * s_stride; const uint8_t* row1 = (row + 1 < h) ? (s + (row + 1) * s_stride) : row0; uint8_t* y0 = y + row * y_stride; uint8_t* y1 = (row + 1 < h) ? (y + (row + 1) * y_stride) : y0; - uint8_t* uu = u + (row / 2) * u_stride; - uint8_t* vv = v + (row / 2) * v_stride; + const int uv_row = row / 2; + uint8_t* uu = (uv_row < uv_h) ? (u + uv_row * u_stride) : nullptr; + uint8_t* vv = (uv_row < uv_h) ? (v + uv_row * v_stride) : nullptr; for (int col = 0; col < w; col += 2) { int u_sum = 0; @@ -162,8 +166,10 @@ bool FillYuv420pFromFrame(const Frame& src, AVFrame* dst) { const int u_val = ((u_sum / denom) + 128 * 256 + 128) >> 8; const int v_val = ((v_sum / denom) + 128 * 256 + 128) >> 8; const int uv_col = col / 2; - uu[uv_col] = ClipU8(u_val); - vv[uv_col] = ClipU8(v_val); + if (uu && vv && uv_col >= 0 && uv_col < uv_w) { + uu[uv_col] = ClipU8(u_val); + vv[uv_col] = ClipU8(v_val); + } } } return true;