Commit 57bd9da446 for aom

commit 57bd9da446bb4e5ae7916d2046ea2b229b579cce
Author: Lin Zheng <linzhen@google.com>
Date:   Mon Nov 23 21:03:09 2026 +0000

    Fix dangling stack pointer in av1_enc_build_inter_predictor

    When ctx is NULL, is_interintra_pred(xd->mi[0]) is true, and
    plane_from < plane_to, assigning ctx = &default_ctx inside the
    per-plane if block left ctx pointing to a destroyed stack variable
    on subsequent loop iterations (flagged by Clang's
    -Wlifetime-safety-use-after-scope).

    Hoist both the loop-invariant is_interintra_pred(xd->mi[0]) check and
    default_ctx outside the plane loop, initializing default_ctx only when
    is_interintra && !ctx so non-interintra and non-NULL ctx callers pay no
    extra loads/stores.

    Bug: b:585665749
    Change-Id: If4c848bbbadfa9c1570eae039811ab4285c1b9df

diff --git a/av1/encoder/reconinter_enc.c b/av1/encoder/reconinter_enc.c
index 825e17c2fa..2e027ee0dd 100644
--- a/av1/encoder/reconinter_enc.c
+++ b/av1/encoder/reconinter_enc.c
@@ -112,6 +112,15 @@ void av1_enc_build_inter_predictor(const AV1_COMMON *cm, MACROBLOCKD *xd,
                                    int mi_row, int mi_col,
                                    const BUFFER_SET *ctx, BLOCK_SIZE bsize,
                                    int plane_from, int plane_to) {
+  const int is_interintra = is_interintra_pred(xd->mi[0]);
+  BUFFER_SET default_ctx;
+  if (is_interintra && !ctx) {
+    for (int i = 0; i < MAX_MB_PLANE; ++i) {
+      default_ctx.plane[i] = xd->plane[i].dst.buf;
+      default_ctx.stride[i] = xd->plane[i].dst.stride;
+    }
+    ctx = &default_ctx;
+  }
   for (int plane = plane_from; plane <= plane_to; ++plane) {
     if (plane && !xd->is_chroma_ref) break;
     const int mi_x = mi_col * MI_SIZE;
@@ -119,15 +128,7 @@ void av1_enc_build_inter_predictor(const AV1_COMMON *cm, MACROBLOCKD *xd,
     enc_build_inter_predictors(cm, xd, plane, xd->mi[0], xd->plane[plane].width,
                                xd->plane[plane].height, mi_x, mi_y);

-    if (is_interintra_pred(xd->mi[0])) {
-      BUFFER_SET default_ctx = {
-        { xd->plane[0].dst.buf, xd->plane[1].dst.buf, xd->plane[2].dst.buf },
-        { xd->plane[0].dst.stride, xd->plane[1].dst.stride,
-          xd->plane[2].dst.stride }
-      };
-      if (!ctx) {
-        ctx = &default_ctx;
-      }
+    if (is_interintra) {
       av1_build_interintra_predictor(cm, xd, xd->plane[plane].dst.buf,
                                      xd->plane[plane].dst.stride, ctx, plane,
                                      bsize);