cpp_demangle icon indicating copy to clipboard operation
cpp_demangle copied to clipboard

Allow users to specify a maximum length for the demangled symbol

Open fitzgen opened this issue 8 years ago • 2 comments

Since the demangled symbol's length can be exponential in the worst case, we should allow users to clamp it down.

For example, this mangled symbol

__Z20lets_get_exponentialP4PairIS_IS_IS_IS_IS_IS_IS_IiiES0_ES1_ES2_ES3_ES4_ES5_ES6_E

Demangles into this:

lets_get_exponential(Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > >, Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > > >, Pair<Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > >, Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > > > >, Pair<Pair<Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > >, Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > > >, Pair<Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > >, Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > > > > >, Pair<Pair<Pair<Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > >, Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > > >, Pair<Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > >, Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > > > >, Pair<Pair<Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > >, Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > > >, Pair<Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > >, Pair<Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > >, Pair<Pair<Pair<int, int>, Pair<int, int> >, Pair<Pair<int, int>, Pair<int, int> > > > > > > >*)

fitzgen avatar Feb 19 '17 18:02 fitzgen

Also see https://twitter.com/whitequark/status/952840692233048065

crepererum avatar Aug 28 '18 17:08 crepererum

FWIW, one can do this now with a custom Write impl wrapper to demangle into that enforces a max number of bytes to forward to its underlying writer and errors if anything attempts to write more than that.

fitzgen avatar Aug 28 '18 17:08 fitzgen