Skip to content

Commit a7d0b7a

Browse files
committed
ld128 demangle: allow space for 'L' suffix.
Summary: Caught by HWASAN on arm64 Android (which uses ld128 for long double). This was running the existing fuzzer. The specific minimized fuzz input to reproduce this is: __cxa_demangle("1\006ILeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE", 0, 0, 0); Reviewers: eugenis, srhines, #libc_abi! Subscribers: kristof.beyls, danielkiss, libcxx-commits Tags: #libc_abi Differential Revision: https://reviews.llvm.org/D77924
1 parent 592b899 commit a7d0b7a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

libcxxabi/src/demangle/ItaniumDemangle.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5203,7 +5203,12 @@ struct FloatData<long double>
52035203
#else
52045204
static const size_t mangled_size = 20; // May need to be adjusted to 16 or 24 on other platforms
52055205
#endif
5206-
static const size_t max_demangled_size = 40;
5206+
// `-0x1.ffffffffffffffffffffffffffffp+16383` + 'L' + '\0' == 42 bytes.
5207+
// 28 'f's * 4 bits == 112 bits, which is the number of mantissa bits.
5208+
// Negatives are one character longer than positives.
5209+
// `0x1.` and `p` are constant, and exponents `+16383` and `-16382` are the
5210+
// same length. 1 sign bit, 112 mantissa bits, and 15 exponent bits == 128.
5211+
static const size_t max_demangled_size = 42;
52075212
static constexpr const char *spec = "%LaL";
52085213
};
52095214

libcxxabi/test/test_demangle.pass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
// Is long double fp80? (Only x87 extended double has 64-bit mantissa)
1717
#define LDBL_FP80 (__LDBL_MANT_DIG__ == 64)
18+
// Is long double fp128?
19+
#define LDBL_FP128 (__LDBL_MANT_DIG__ == 113)
1820

1921
const char* cases[][2] =
2022
{
@@ -29837,6 +29839,11 @@ struct FPLiteralCase {
2983729839
"void test0::h<float>(char (&) [(unsigned int)((sizeof (float)) + (0xap-1L))])",
2983829840
}},
2983929841
#endif
29842+
#if LDBL_FP128
29843+
// This was found by libFuzzer+HWASan on aarch64 Android.
29844+
{"1\006ILeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
29845+
{"\x6<-0x1.cecececececececececececececep+11983"}},
29846+
#endif
2984029847
};
2984129848
const unsigned NF = sizeof(fp_literal_cases) / sizeof(fp_literal_cases[0]);
2984229849
const unsigned NEF = sizeof(fp_literal_cases[0].expecting) / sizeof(fp_literal_cases[0].expecting[0]);

llvm/include/llvm/Demangle/ItaniumDemangle.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5203,7 +5203,12 @@ struct FloatData<long double>
52035203
#else
52045204
static const size_t mangled_size = 20; // May need to be adjusted to 16 or 24 on other platforms
52055205
#endif
5206-
static const size_t max_demangled_size = 40;
5206+
// `-0x1.ffffffffffffffffffffffffffffp+16383` + 'L' + '\0' == 42 bytes.
5207+
// 28 'f's * 4 bits == 112 bits, which is the number of mantissa bits.
5208+
// Negatives are one character longer than positives.
5209+
// `0x1.` and `p` are constant, and exponents `+16383` and `-16382` are the
5210+
// same length. 1 sign bit, 112 mantissa bits, and 15 exponent bits == 128.
5211+
static const size_t max_demangled_size = 42;
52075212
static constexpr const char *spec = "%LaL";
52085213
};
52095214

0 commit comments

Comments
 (0)