The rust demangler can be pushed into an infinite loop, triggering stack exhaustion: % cat pr27963 # Reproduced from binutils PR 27963. # Note - the expected output is wrong. It is just there as a placeholder. --format=rust _RIMBALO_suB_I__Z5printi fred % valgrind ./testsuite/test-demangle < pr27963 [...] ==429737== Stack overflow in thread #1: can't grow stack to 0x1ffe001000 [...] =429737== Stack overflow in thread #1: can't grow stack to 0x1ffe001000 ==429737== at 0x410BA7: demangle_path (rust-demangle.c:742) [...] Segmentation fault (core dumped)
Created attachment 50777 [details] Proposed patch Here is a possible patch for the problem, adding a recursion limit to the demangle_path() function. Note - a variation of this bug appears to have been reported on the Ubuntu mailing lists with a different reproducer: https://bugs.launchpad.net/ubuntu/+source/binutils/+bug/1925348
This patch breaks MinGW, see PR 101779
(In reply to Jonathan Wakely from comment #2) > This patch breaks MinGW, see PR 101779 But it can be fixed by: https://sourceware.org/bugzilla/show_bug.cgi?id=28207
*** Bug 104185 has been marked as a duplicate of this bug. ***
*** Bug 104186 has been marked as a duplicate of this bug. ***
*** Bug 101779 has been marked as a duplicate of this bug. ***
*** Bug 98889 has been marked as a duplicate of this bug. ***
*** Bug 100968 has been marked as a duplicate of this bug. ***
A revised patch to fix this PR has been prroposed on gcc-patches: https://gcc.gnu.org/pipermail/gcc-patches/2022-January/589277.html
The master branch has been updated by Nick Clifton <nickc@gcc.gnu.org>: https://gcc.gnu.org/g:f10bec5ffa487ad3033ed5f38cfd0fc7d696deab commit r12-6945-gf10bec5ffa487ad3033ed5f38cfd0fc7d696deab Author: Nick Clifton <nickc@redhat.com> Date: Mon Jan 31 14:28:42 2022 +0000 libiberty: Fix infinite recursion in rust demangler. libiberty/ PR demangler/98886 PR demangler/99935 * rust-demangle.c (struct rust_demangler): Add a recursion counter. (demangle_path): Increment/decrement the recursion counter upon entry and exit. Fail if the counter exceeds a fixed limit. (demangle_type): Likewise. (rust_demangle_callback): Initialise the recursion counter, disabling if requested by the option flags.
Fixed on mainline.