[Bug][TIR] `s_tir.Schedule.cache_read` omits domain bounds predicate on shifted conditional reads, causing negative-index heap buffer underflow (`SIGABRT`/`SIGSEGV`)
Los mantenedores suelen responder en 3 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 57/100
Línea de trabajo
Start in src/s_tir/schedule/primitive/cache_read_write.cc, in MakeCacheStage, and compare its cache block predicate with predicate generation in ComputeAt. Use the supplied reproduction to inspect the scheduled B_local block and confirm the missing bounds predicate causes the negative index. Done means the cache copy preserves bounds safety and the reproduction exits successfully with the expected results.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Expected behavior
Applying valid S-TIR primitives (split, compute_at, cache_read) to a producer-consumer PrimFunc where the consumer conditionally reads a shifted index (T.if_then_else(4 <= v0, B[v0 - 4, v1], A[v0, v1])) must preserve bounds safety and produce identical results (sum=12288.0, exit code 0).
Actual behavior
s_tir.Schedule.cache_read generates an unguarded B_local cache-copy block with v0 = T.axis.spatial(2, ax0 - 4 + ax0_1) and predicate = true (missing T.where(4 <= ax0)), even though the adjacent compute_at producer block in the same loop correctly carries T.where(4 <= ax0).
After CompactBufferAllocation, B and B_local are compacted to (1024,) and unconditionally accessed at negative indices -4096..-1 for ax0 in 0..3:
B_local[ax0 * 1024 + ax1 - T.max(0, ax0 - 4) * 1024 - 4096] = B[...]
At runtime this underflows the heap allocation, corrupting TVM's WorkspacePool and glibc heap metadata and crashing with SIGABRT (corrupted double-linked list / double free or corruption (out)) or SIGSEGV depending on heap layout.
Environment
- TVM:
0.27.0(7b5acb32bd271342a24130f4ef439ff6c2e52c6c) - Upstream status: verified still unfixed on
apache/tvmmain(84657c01e5d3672cfd299bd3d5c77bff3888a1a9, 2026-12-02) - OS: Linux x86_64
Steps to reproduce
import numpy as np
import tvm
from tvm import s_tir
from tvm.script import tirx as T
@T.prim_func(s_tir=True)
def slice_then_concat(
X: T.Buffer((T.int64(5), T.int64(2048)), "float32"),
A: T.Buffer((T.int64(4), T.int64(2048)), "float32"),
C: T.Buffer((T.int64(6), T.int64(2048)), "float32"),
):
B = T.sblock_alloc_buffer((T.int64(2), T.int64(2048)), "float32")
for ax0, ax1 in T.grid(T.int64(2), T.int64(2048)):
with T.sblock("slice"):
v0, v1 = T.axis.remap("SS", [ax0, ax1])
B[v0, v1] = X[v0 + T.int64(3), v1]
for ax0, ax1 in T.grid(T.int64(6), T.int64(2048)):
with T.sblock("concat"):
v0, v1 = T.axis.remap("SS", [ax0, ax1])
C[v0, v1] = T.if_then_else(T.int64(4) <= v0, B[v0 - T.int64(4), v1], A[v0, v1])
sch = s_tir.Schedule(slice_then_concat)
blk_s = sch.get_sblock("slice")
blk_c = sch.get_sblock("concat")
_, l1 = sch.get_loops(blk_c)
l1_o, _ = sch.split(l1, factors=[None, 1024])
sch.compute_at(blk_s, l1_o, preserve_unit_loops=True)
sch.cache_read(blk_c, 0, "local")
f = tvm.compile(sch.mod, target="llvm")
f(
tvm.runtime.tensor(np.ones((5, 2048), "float32")),
tvm.runtime.tensor(np.ones((4, 2048), "float32")),
tvm.runtime.tensor(np.zeros((6, 2048), "float32")),
)
# Crashes with SIGABRT (e.g. corrupted double-linked list / double free or corruption) or SIGSEGV
Suggested fix
In src/s_tir/schedule/primitive/cache_read_write.cc (MakeCacheStage), derive the SBlockRealize predicate from the domain bounds of each cache block iter var (0 <= iter_value < dom->extent, matching compute_at / ComputeAt predicate generation) rather than hardcoding IntImm::Bool(true).
- Lenguaje dominante
- Python
- Estrellas
- 13.9k
- Forks
- 4.1k
- Merge medio
- 4 d 22 h
- PR fusionados (30 d)
- 22
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/tvm
-
[Bug] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is NonePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 3 días
-
[Bug][TOPI] `topi.scanop` (`cumsum` / `cumprod`) performs out-of-bounds write/read on empty tensorsAbiertoneeds-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 3 días
-
[Bug] [Relax] take_backward does not normalize negative axis causing heap OOB write and wrong gradientsPosiblemente ocupada @pierceluu10 la tomó hace 4 días. Abiertoneeds-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 3 días
-
[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputsPosiblemente ocupada @tandede la tomó hace 9 días. Abiertoneeds-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 3 días
-
needs-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
apache/tvm#21043 · 1 comentario ·
Los mantenedores suelen responder en 3 días
Todos los issues de apache/tvm
Issues similares
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
web-push-libs/pywebpush#216 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
AgriciDaniel/claude-seo#572 ·
Los mantenedores suelen responder en 5 días
-
area:print-dispatch
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
Los mantenedores suelen responder en 1 día
-
area: docs domain: technical-writing good first issue type: documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Deepak3699/Ai_Mentor#919 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día