Commit f0fcd42
[libc++abi] Fix possible infinite loop in itanium demangler
A libfuzzer run has discovered some inputs for which the demangler does
not terminate. When minimized, it looks like this: _Zcv1BIRT_EIS1_E
Deciphered:
_Z
cv - conversion operator
* result type
1B - "B"
I - template args begin
R - reference type <.
T_ - forward template reference | *
E - template args end | |
| |
* parameter type | |
I - template args begin | |
S1_ - substitution #1 * <'
E - template args end
The reason is: template-parameter refs in conversion operator result type
create forward-references, while substitutions are instantly resolved via
back-references. Together these can create a reference loop. It causes an
infinite loop in ReferenceType::collapse().
I see three possible ways to avoid these loops:
1. check if resolving a forward reference creates a loop and reject the
invalid input (hard to traverse AST at this point)
2. check if a substitution contains a malicious forward reference and
reject the invalid input (hard to traverse AST at this point;
substitutions are quite common: may affect performance; hard to
clearly detect loops at this point)
3. detect loops in ReferenceType::collapse() (cannot reject the input)
This patch implements (3) as seemingly the least-impact change. As a
side effect, such invalid input strings are not rejected and produce
garbage, however there are already similar guards in
`if (Printing) return;` checks.
Fixes https://llvm.org/PR51407
Differential Revision: https://reviews.llvm.org/D1077121 parent db7c68d commit f0fcd42
File tree
3 files changed
+46
-0
lines changed- libcxxabi
- src/demangle
- test
- llvm/include/llvm/Demangle
3 files changed
+46
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
651 | 651 | | |
652 | 652 | | |
653 | 653 | | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
654 | 658 | | |
655 | 659 | | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
656 | 663 | | |
657 | 664 | | |
658 | 665 | | |
659 | 666 | | |
660 | 667 | | |
661 | 668 | | |
662 | 669 | | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
663 | 678 | | |
664 | 679 | | |
665 | 680 | | |
| |||
680 | 695 | | |
681 | 696 | | |
682 | 697 | | |
| 698 | + | |
| 699 | + | |
683 | 700 | | |
684 | 701 | | |
685 | 702 | | |
| |||
693 | 710 | | |
694 | 711 | | |
695 | 712 | | |
| 713 | + | |
| 714 | + | |
696 | 715 | | |
697 | 716 | | |
698 | 717 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
12 | 17 | | |
13 | 18 | | |
14 | 19 | | |
| |||
29844 | 29849 | | |
29845 | 29850 | | |
29846 | 29851 | | |
| 29852 | + | |
| 29853 | + | |
| 29854 | + | |
29847 | 29855 | | |
29848 | 29856 | | |
29849 | 29857 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
651 | 651 | | |
652 | 652 | | |
653 | 653 | | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
654 | 658 | | |
655 | 659 | | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
656 | 663 | | |
657 | 664 | | |
658 | 665 | | |
659 | 666 | | |
660 | 667 | | |
661 | 668 | | |
662 | 669 | | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
663 | 678 | | |
664 | 679 | | |
665 | 680 | | |
| |||
680 | 695 | | |
681 | 696 | | |
682 | 697 | | |
| 698 | + | |
| 699 | + | |
683 | 700 | | |
684 | 701 | | |
685 | 702 | | |
| |||
693 | 710 | | |
694 | 711 | | |
695 | 712 | | |
| 713 | + | |
| 714 | + | |
696 | 715 | | |
697 | 716 | | |
698 | 717 | | |
| |||
0 commit comments