8000 `string repeat` has an infinite loop · Issue #9899 · fish-shell/fish-shell · GitHub
[go: up one dir, main page]

Skip to content

string repeat has an infinite loop #9899

@dwawlyn

Description

@dwawlyn

[
fish --version
#=>
fish, version 3.6.1

uname -a
#=>
Linux hostname 6.4.2-1-default #1 SMP PREEMPT_DYNAMIC Mon Jul 10 10:03:25 UTC 2023 (b97b894) x86_64 x86_64 x86_64 GNU/Linux

echo $TERM
#=>
xterm-256color

(opensuse tumbleweed)
]

I just ran into this while throwing together a quick test for how another program (ag) behaves with different line lengths.
(ie, just to give context of how I stumbled on this fish thing, this otherwise unrelated issue with ag x --print-long-lines.)

I originally set up the test using line lengths of 2 20 200 2000 20000
(
$

for n in 2 20 200 2000 20000
	echo (string repeat -n (math "$n-1") _)x > file_$n.txt
end

)
and it worked fine...

But when I tried to bump that upper 20000 down to a mere 3000
(cuz fun github fact, apparently "There was an error creating your Issue: body is too long (maximum is 65536 characters).")
(
$

for n in 2 20 200 2000 3000
	echo (string repeat -n (math "$n-1") _)x > file_$n.txt
end

)
I got the error:

Too much data emitted by command substitution so it was discarded
        echo (string repeat -n (math "$n-1") _)x > file_$n.txt
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I was utterly mystified that the code worked with 20k characters,
but a mere 3k was apparently too much,
but skipping over the rest of the story of how I stumbled through isolating the problem more and more,
I ended up testing for completeness sake up to the highest number I practically could,
which was 524288
(
cuz in the following for-loop I used,
that was the highest that doesn't result in the error:
fish: Expansion produced too many results
which by contrast is an entirely straightforward and comprehensible limitation that I wouldn't even really call a "bug"...
)

So I ran this test:
$

echo -n > failures
for n in (seq 1 524288)
	if echo (string repeat -n $n _)x &>/dev/null
		echo OK $n
	else
		echo FAIL $n | tee -a failures
	end
end

which got specifically 348 numbers it fails for...

In summary, the pattern looks like (for $n, and $n+1:

$n  	=	2999,4499,5999,7499,8999,10499,11999,[...],514499,515999,517499,518999,520499,521999,523499
$n+1	=	3000,4500,6000,7500,9000,10500,12000,[...],514500,516000,517500,519000,520500,522000,523500

Which... looks like there's some clear and obvious pattern to it,
but damned if I'd have a clue where it comes from.

Reformatting the output a bit, the full list is:

#	    	# actual $n in my test	# $n+1	
 	FAIL	  2999                	  3000	
 	FAIL	  4499                	  4500	
 	FAIL	  5999                	  6000	
 	FAIL	  7499                	  7500	
 	FAIL	  8999                	  9000	
 	FAIL	 10499                	 10500	
 	FAIL	 11999                	 12000	
 	FAIL	 13499                	 13500	
 	FAIL	 14999                	 15000	
 	FAIL	 16499                	 16500	
 	FAIL	 17999                	 18000	
 	FAIL	 19499                	 19500	
 	FAIL	 20999                	 21000	
 	FAIL	 22499                	 22500	
 	FAIL	 23999                	 24000	
 	FAIL	 25499                	 25500	
 	FAIL	 26999                	 27000	
 	FAIL	 28499                	 28500	
 	FAIL	 29999                	 30000	
 	FAIL	 31499                	 31500	
 	FAIL	 32999                	 33000	
 	FAIL	 34499                	 34500	
 	FAIL	 35999                	 36000	
 	FAIL	 37499                	 37500	
 	FAIL	 38999                	 39000	
 	FAIL	 40499                	 40500	
 	FAIL	 41999                	 42000	
 	FAIL	 43499                	 43500	
 	FAIL	 44999                	 45000	
 	FAIL	 46499                	 46500	
 	FAIL	 47999                	 48000	
 	FAIL	 49499                	 49500	
 	FAIL	 50999                	 51000	
 	FAIL	 52499                	 52500	
 	FAIL	 53999                	 54000	
 	FAIL	 55499                	 55500	
 	FAIL	 56999                	 57000	
 	FAIL	 58499                	 58500	
 	FAIL	 59999                	 60000	
 	FAIL	 61499                	 61500	
 	FAIL	 62999                	 63000	
 	FAIL	 64499                	 64500	
 	FAIL	 65999                	 66000	
 	FAIL	 67499                	 67500	
 	FAIL	 68999                	 69000	
 	FAIL	 70499                	 70500	
 	FAIL	 71999                	 72000	
 	FAIL	 73499                	 73500	
 	FAIL	 74999                	 75000	
 	FAIL	 76499                	 76500	
 	FAIL	 77999                	 78000	
 	FAIL	 79499                	 79500	
 	FAIL	 80999                	 81000	
 	FAIL	 82499                	 82500	
 	FAIL	 83999                	 84000	
 	FAIL	 85499                	 85500	
 	FAIL	 86999                	 87000	
 	FAIL	 88499                	 88500	
 	FAIL	 89999                	 90000	
 	FAIL	 91499                	 91500	
 	FAIL	 92999                	 93000	
 	FAIL	 94499                	 94500	
 	FAIL	 95999                	 96000	
 	FAIL	 97499                	 97500	
 	FAIL	 98999                	 99000	
 	FAIL	100499                	100500	
 	FAIL	101999                	102000	
 	FAIL	103499                	103500	
 	FAIL	104999                	105000	
 	FAIL	106499                	106500	
 	FAIL	107999                	108000	
 	FAIL	109499                	109500	
 	FAIL	110999                	111000	
 	FAIL	112499                	112500	
 	FAIL	113999                	114000	
 	FAIL	115499                	115500	
 	FAIL	116999                	117000	
 	FAIL	118499                	118500	
 	FAIL	119999                	120000	
 	FAIL	121499                	121500	
 	FAIL	122999                	123000	
 	FAIL	124499                	124500	
 	FAIL	125999                	126000	
 	FAIL	127499                	127500	
 	FAIL	128999                	129000	
 	FAIL	130499                	130500	
 	FAIL	131999                	132000	
 	FAIL	133499                	133500	
 	FAIL	134999                	135000	
 	FAIL	136499                	136500	
 	FAIL	137999                	138000	
 	FAIL	139499                	139500	
 	FAIL	140999                	141000	
 	FAIL	142499                	142500	
 	FAIL	143999                	144000	
 	FAIL	145499                	145500	
 	FAIL	146999                	147000	
 	FAIL	148499                	148500	
 	FAIL	149999                	150000	
 	FAIL	151499                	151500	
 	FAIL	152999                	153000	
 	FAIL	154499                	154500	
 	FAIL	155999                	156000	
 	FAIL	157499                	157500	
 	FAIL	158999                	159000	
 	FAIL	160499                	160500	
 	FAIL	161999                	162000	
 	FAIL	163499                	163500	
 	FAIL	164999                	165000	
 	FAIL	166499                	166500	
 	FAIL	167999                	168000	
 	FAIL	169499                	169500	
 	FAIL	170999                	171000	
 	FAIL	172499                	172500	
 	FAIL	173999                	174000	
 	FAIL	175499                	175500	
 	FAIL	176999                	177000	
 	FAIL	178499                	178500	
 	FAIL	179999                	180000	
 	FAIL	181499                	181500	
 	FAIL	182999                	183000	
 	FAIL	184499                	184500	
 	FAIL	185999                	186000	
 	FAIL	187499                	187500	
 	FAIL	188999                	189000	
 	FAIL	190499                	190500	
 	FAIL	191999                	192000	
 	FAIL	193499                	193500	
 	FAIL	194999                	195000	
 	FAIL	196499                	196500	
 	FAIL	197999                	198000	
 	FAIL	199499                	199500	
 	FAIL	200999                	201000	
 	FAIL	202499                	202500	
 	FAIL	203999                	204000	
 	FAIL	205499                	205500	
 	FAIL	206999                	207000	
 	FAIL	208499                	208500	
 	FAIL	209999                	210000	
 	FAIL	211499                	211500	
 	FAIL	212999                	213000	
 	FAIL	214499                	214500	
 	FAIL	215999                	216000	
 	FAIL	217499                	217500	
 	FAIL	218999                	219000	
 	FAIL	220499                	220500	
 	FAIL	221999                	222000	
 	FAIL	223499                	223500	
 	FAIL	224999                	225000	
 	FAIL	226499                	226500	
 	FAIL	227999                	228000	
 	FAIL	229499                	229500	
 	FAIL	230999                	231000	
 	FAIL	232499                	232500	
 	FAIL	233999                	234000	
 	FAIL	235499                	235500	
 	FAIL	236999                	237000	
 	FAIL	238499                	238500	
 	FAIL	239999                	240000	
 	FAIL	241499                	241500	
 	FAIL	242999                	243000	
 	FAIL	244499                	244500	
 	FAIL	245999                	246000	
 	FAIL	247499                	247500	
 	FAIL	248999                	249000	
 	FAIL	250499                	250500	
 	FAIL	251999                	252000	
 	FAIL	253499                	253500	
 	FAIL	254999                	255000	
 	FAIL	256499                	256500	
 	FAIL	257999                	258000	
 	FAIL	259499                	259500	
 	FAIL	260999           
8903
     	261000	
 	FAIL	262499                	262500	
 	FAIL	263999                	264000	
 	FAIL	265499                	265500	
 	FAIL	266999                	267000	
 	FAIL	268499                	268500	
 	FAIL	269999                	270000	
 	FAIL	271499                	271500	
 	FAIL	272999                	273000	
 	FAIL	274499                	274500	
 	FAIL	275999                	276000	
 	FAIL	277499                	277500	
 	FAIL	278999                	279000	
 	FAIL	280499                	280500	
 	FAIL	281999                	282000	
 	FAIL	283499                	283500	
 	FAIL	284999                	285000	
 	FAIL	286499                	286500	
 	FAIL	287999                	288000	
 	FAIL	289499                	289500	
 	FAIL	290999                	291000	
 	FAIL	292499                	292500	
 	FAIL	293999                	294000	
 	FAIL	295499                	295500	
 	FAIL	296999                	297000	
 	FAIL	298499                	298500	
 	FAIL	299999                	300000	
 	FAIL	301499                	301500	
 	FAIL	302999                	303000	
 	FAIL	304499                	304500	
 	FAIL	305999                	306000	
 	FAIL	307499                	307500	
 	FAIL	308999                	309000	
 	FAIL	310499                	310500	
 	FAIL	311999                	312000	
 	FAIL	313499                	313500	
 	FAIL	314999                	315000	
 	FAIL	316499                	316500	
 	FAIL	317999                	318000	
 	FAIL	319499                	319500	
 	FAIL	320999                	321000	
 	FAIL	322499                	322500	
 	FAIL	323999                	324000	
 	FAIL	325499                	325500	
 	FAIL	326999                	327000	
 	FAIL	328499                	328500	
 	FAIL	329999                	330000	
 	FAIL	331499                	331500	
 	FAIL	332999                	333000	
 	FAIL	334499                	334500	
 	FAIL	335999                	336000	
 	FAIL	337499                	337500	
 	FAIL	338999                	339000	
 	FAIL	340499                	340500	
 	FAIL	341999                	342000	
 	FAIL	343499                	343500	
 	FAIL	344999                	345000	
 	FAIL	346499                	346500	
 	FAIL	347999                	348000	
 	FAIL	349499                	349500	
 	FAIL	350999                	351000	
 	FAIL	352499                	352500	
 	FAIL	353999                	354000	
 	FAIL	355499                	355500	
 	FAIL	356999                	357000	
 	FAIL	358499                	358500	
 	FAIL	359999                	360000	
 	FAIL	361499                	361500	
 	FAIL	362999                	363000	
 	FAIL	364499                	364500	
 	FAIL	365999                	366000	
 	FAIL	367499                	367500	
 	FAIL	368999                	369000	
 	FAIL	370499                	370500	
 	FAIL	371999                	372000	
 	FAIL	373499                	373500	
 	FAIL	374999                	375000	
 	FAIL	376499                	376500	
 	FAIL	377999                	378000	
 	FAIL	379499                	379500	
 	FAIL	380999                	381000	
 	FAIL	382499                	382500	
 	FAIL	383999                	384000	
 	FAIL	385499                	385500	
 	FAIL	386999                	387000	
 	FAIL	388499                	388500	
 	FAIL	389999                	390000	
 	FAIL	391499                	391500	
 	FAIL	392999                	393000	
 	FAIL	394499                	394500	
 	FAIL	395999                	396000	
 	FAIL	397499                	397500	
 	FAIL	398999                	399000	
 	FAIL	400499                	400500	
 	FAIL	401999                	402000	
 	FAIL	403499                	403500	
 	FAIL	404999                	405000	
 	FAIL	406499                	406500	
 	FAIL	407999                	408000	
 	FAIL	409499                	409500	
 	FAIL	410999                	411000	
 	FAIL	412499                	412500	
 	FAIL	413999                	414000	
 	FAIL	415499                	415500	
 	FAIL	416999                	417000	
 	FAIL	418499                	418500	
 	FAIL	419999                	420000	
 	FAIL	421499                	421500	
 	FAIL	422999                	423000	
 	FAIL	424499                	424500	
 	FAIL	425999                	426000	
 	FAIL	427499                	427500	
 	FAIL	428999                	429000	
 	FAIL	430499                	430500	
 	FAIL	431999                	432000	
 	FAIL	433499                	433500	
 	FAIL	434999                	435000	
 	FAIL	436499                	436500	
 	FAIL	437999                	438000	
 	FAIL	439499                	439500	
 	FAIL	440999                	441000	
 	FAIL	442499                	442500	
 	FAIL	443999                	444000	
 	FAIL	445499                	445500	
 	FAIL	446999                	447000	
 	FAIL	448499                	448500	
 	FAIL	449999                	450000	
 	FAIL	451499                	451500	
 	FAIL	452999                	453000	
 	FAIL	454499                	454500	
 	FAIL	455999                	456000	
 	FAIL	457499                	457500	
 	FAIL	458999                	459000	
 	FAIL	460499                	460500	
 	FAIL	461999                	462000	
 	FAIL	463499                	463500	
 	FAIL	464999                	465000	
 	FAIL	466499                	466500	
 	FAIL	467999                	468000	
 	FAIL	469499                	469500	
 	FAIL	470999                	471000	
 	FAIL	472499                	472500	
 	FAIL	473999                	474000	
 	FAIL	475499                	475500	
 	FAIL	476999                	477000	
 	FAIL	478499                	478500	
 	FAIL	479999                	480000	
 	FAIL	481499                	481500	
 	FAIL	482999                	483000	
 	FAIL	484499                	484500	
 	FAIL	485999                	486000	
 	FAIL	487499                	487500	
 	FAIL	488999                	489000	
 	FAIL	490499                	490500	
 	FAIL	491999                	492000	
 	FAIL	493499                	493500	
 	FAIL	494999                	495000	
 	FAIL	496499                	496500	
 	FAIL	497999                	498000	
 	FAIL	499499                	499500	
 	FAIL	500999                	501000	
 	FAIL	502499                	502500	
 	FAIL	503999                	504000	
 	FAIL	505499                	505500	
 	FAIL	506999                	507000	
 	FAIL	508499                	508500	
 	FAIL	509999                	510000	
 	FAIL	511499                	511500	
 	FAIL	512999                	513000	
 	FAIL	514499                	514500	
 	FAIL	515999                	516000	
 	FAIL	517499                	517500	
 	FAIL	518999                	519000	
 	FAIL	520499                	520500	
 	FAIL	521999                	522000	
 	FAIL	523499                	523500	

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that's not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0