While testing my shell wrapper inshell I believe I have come across a bug in Stata (I'm running Stata/SE 17.0 for Mac (Intel 64-bit), Revision 13 Oct 2022). I had written a program to generate random strings using ASCII character codes 32 to 126 and kept the ones containing dollars signs ($), backticks (`), and double quotes ("), then tested each one to see if inshell could echo (and subsequently capture) it. Some examples are presented below:
After about 5000 successful tests with similar strings I found that certain of these would crash Stata, requiring a force quit. Upon further inspection, I noticed that all of these strings had one thing in common: unbalanced curly braces ({}). Take for example these two strings:
Though the string can be stored it cannot be displayed. In my particular case, if the string is contained in an external file which inshell reads , it will crash when attempting to store that string as a returned macro. However, any Stata user should be able to reproduce the issue with the following code:
WARNING! the following code is likely to crash your copy of Stata and possibly your machine:
This will happen even if the string is stored as a scalar. String parsing functions will still work, such as:
Can anyone else reproduce this? I'm assuming that Stata is attempting to display what it thinks are SMCL directives, however the _asis option to display does not change this.
Code:
$jR'2a;RD8VdEM\peyskw't^ n2R$+eaHQkvtNAo-CseTU/0g ^=wuRQgsdeRaMJjh$-3on05^ wup5@C':Pm=ndcDkH=o="+at u4.~.A~weH-gcI(ln`w08;Wi ,~^G<A@Z6+#0$`qb[*|m,daU Op<|U`GF4;hZLFmf5BI%4!a~ LC"3,=#y3zwj^U`\W_HC%~)N $#qApyEN4hG@C#AML}QW7ZD~ $e.wv]p^}/txI,d+>Sq<XIXr
Code:
j1W|671}O/|Deo{?$$E*s}R8 }CW{?`_)AFp}gJPbgCkdPj_9
WARNING! the following code is likely to crash your copy of Stata and possibly your machine:
Code:
local test_string "}CW{?`_)AFp}gJPbgCkdPj_9" macro list _test_string display "`macval(test_string)'" // this will crash Stata display "`test_string'" _asis // this will also crash Stata
Code:
display strpos("`test_string'", "A") 9
Comment