<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">Hello guys,</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">apparently
 it possible for tcsh create a corrupted ~/.history file, which can 
reach huge sizes. Our customer provided us with their ~/.history file 
which is corrupted and causing OOM problems when running multiple 
instances of tcsh simultaneously. Checking the file, I can't even open 
it in Vim (or anything else actually), because it has size of 4 GiB.<br><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">My
 colleague dealing with this before was able to find out, that at one 
point (because of this corrupted file), tcsh was trying to allocate more
 than 0.5 GiB for just one line (string) from that file, which has 
failed because of not sufficient memory.</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">This
 is apparently a corner case, and traditional users will most likely 
never be impacted by this behaviour. However, in production 
environments, this can happen much often I reckon.<br><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">So
 the idea that came up was to discard the ~/.history file, when it 
reaches some unreasonable size like this, and especially when the size 
of one line (string) is over some reasonable limit (e.g. lets say 8 KiB 
or similar). I think it safe to assume that at that point the ~/.history
 file can no longer serve its purpose.<br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">Before
 I get into writing some patch, I would like to know if you would agree 
with this proposed solution? Or do you have any better idea how to deal 
with corner case?<br><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">Here's the bug report we received, if you want to check details: <a href="https://bugzilla.redhat.com/show_bug.cgi?id=1598502" target="_blank">https://bugzilla.redhat.com/show_bug.cgi?id=1598502</a><br><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">I
 will have to ask customer if it would be possible to share the 
corrupted ~/.history file in case you would like to reproduce this 
yourself.</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">EDIT: I was looking into the lexical analyzer, but I can't make much sense of it. The only thing that I got working for me was this:</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">----------------------<br></div></div></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">diff --git a/sh.lex.c b/sh.lex.c<br>index fee790a..3160bc1 100644<br>--- a/sh.lex.c<br>+++ b/sh.lex.c<br>@@ -183,8 +183,14 @@ lex(struct wordent *hp)<br>     cleanup_ignore(hp);<br>     cleanup_until(hp);<br>     Strbuf_terminate(&histline);<br>+<br>+    if (histline.len >= INBUFSIZE) {<br>+        return (hadhist);<br>+    }<br>+<br>     if (histline.len != 0 && histline.s[histline.len - 1] == '\n')<br>        histline.s[histline.len - 1] = '\0';<br>+<br>     histvalid = 1;<br> <br>     return (hadhist);</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">----------------------<br><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">With this, it was able to process the corrupted 4 GiB .history file eventually (took several seconds), and then when exiting the tcsh, it created "only" 138 MiB .history file. However, I guess this is not the way you would like to fix it...</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small">With kind regards,<br><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"></div></div></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small"><br clear="all"></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div><div><span style="font-family:monospace,monospace">David Kaspar [Dee'Kej]</span><i><span style="font-family:monospace,monospace"><br>Associate Software Engineer</span></i><span style="font-family:monospace,monospace"><i><br>Brno, Czech Republic</i></span><br><span style="font-family:monospace,monospace"></span></div></div><span style="font-family:monospace,monospace"><br></span></div><span style="font-family:monospace,monospace"><span style="color:rgb(204,0,0)">RED HAT</span> | <span style="color:rgb(204,0,0)">TRIED</span>. <span style="color:rgb(204,0,0)">TESTED</span>. <span style="color:rgb(204,0,0)">TRUSTED</span>.<br>Every airline in the Fortune 500 relies on Red Hat.<br>Find out why at <a href="http://www.redhat.com/en/about/trusted" target="_blank">Trusted | Red Hat</a>.<br></span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>