You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_to_dim_order_copy between complex64 and complex128 gives wrong values or corrupts the heap #25902
When the input and the output of the portable _to_dim_order_copy kernel are both complex, it picks the C++ type from the input only (ET_SWITCH_COMPLEXH_TYPES(self.scalar_type(), ...) then _to_dim_order_copy_impl<CTYPE, CTYPE>, kernels/portable/cpu/op__to_dim_order_copy.cpp). So x.to(torch.complex128) on a complex64 tensor writes 8-byte elements into a 16-byte-per-element buffer, and x.to(torch.complex64) on a complex128 tensor writes twice the size of the output buffer. Nothing checks that the two complex dtypes match. I found this by reading the kernel and confirmed it with:
tensor([2.0000-512.0001j, 0.0000+0.0000j], dtype=torch.complex128)
free(): invalid next size (normal)
The second call aborts the process (exit code 134, or 139 on another run). The existing tests only cover complex to complex conversions of the same width. I have a fix with tests and will open a PR linked to this issue.
Versions
ExecuTorch built from main at 035df43, PyTorch 2.15.0+cpu, Python 3.12.3, Ubuntu 24.04 on WSL2, x86_64.
This issue was written with the help of Claude Code (Anthropic); I verified the reproduction.
Activity