roxen.lists.pike.general

Subject Author Date
Re: Stack Overflow Martin Stjernholm <mast[at]lysator[dot]liu[dot]se> 01-04-2009
<<zenothing[at]hotmail.com>> wrote:

> I wrote a program to get the max-infomation block from html file:
/.../
> Using the attached debug.txt (in the debug.zip, unzip it please) as input, the
> program crashed, and a simple one-line error said: Segmentation fault, no
> call-stack dump at all.

Thanks for the test case. It revealed a bunch of bugs, most of them
related to sprintf("%O",...) formatting during low stack space.
_sprintf's are sensitive since they get called a lot when a backtrace
is formatted, and they tend to recurse a lot too, as you could see
here:

> $ pike t.pike
> t.pike:17: Warning: Unused local variable n.
> C stack overflow.
> /home/peterpan/pike/7.8.116/lib/modules/Parser.pmod/SGML.pike:84:
> Parser.SGML()->SGML()->SGMLatom()->_sprintf(79,mapping[1])
> ... last 1 frames above repeated 918 times ...
/.../
>
describe_backtrace(({backtrace_frame(/home/peterpan/pike/7.8.116/lib/master.pike:3835,

If the error being formatted is a stack overflow then it's easy to get
caught in more stack overflow errors during the formatting due to all
those _sprintf's. This can be quite tricky to protect from properly.

Anyway, I've improved 7.8 now in various places, and made some
essential fixes to 7.4, 7.6 and 7.8. Now your program throws an error
which I hope make more sense to you:

  > d-pike t.pike
  Svalue stack overflow. (99325 of 100000 entries on stack, needed 256 more
entries)
  t.pike:22: /main()->walk(({"\n",SGMLatom(size 1),"
bereitstellen",SGMLatom(size 2)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 1)," auflegen",SGMLatom(size
2)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 1)," einlegen*",SGMLatom(size
2)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 1)," versetzen (in
e%G��%@3e Lage)",SGMLatom(size 2)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 1)," stellen",SGMLatom(size
2)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 1)," spannen (in den
Schraubstock)",SGMLatom(size 2)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 1)," setzen",SGMLatom(size
2)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 1)," hintun",SGMLatom(size
2)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4)}),1)
/.../
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 1)," packen",SGMLatom(size
2)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4)}),1)
  t.pike:37: /main()->walk(({SGMLatom(size 1)," Frachtstück",SGMLatom(size
2)}),1)
  t.pike:37:
      /main()->walk(({"\n\t\t\t",SGMLatom(size 1),"\n\t\t\t",SGMLatom(size
3),"\n\t\t\t\t\t\t\t\t\t",SGMLatom(
      size 4),"\t\t\t\n\t\t\t",SGMLatom(size 3),"\n\n\n\n\n\n",SGMLatom(size
3),,,2}),1)                      
  t.pike:37:
      /main()->walk(({"\n\t\t",SGMLatom(size 0),"\n\t\t",SGMLatom(size
0),"\t\t",SGMLatom(size 1),"\n\t\t",SGM
      Latom(size 13),"\n\t"}),1)                                                
                             
  t.pike:37: /main()->walk(({"\n\t",SGMLatom(size 9),"\n\t\t"}),1)
  t.pike:37:
      /main()->walk(({"\n\t\t",SGMLatom(size 3),"\n\t\t",SGMLatom(size
13),"\n\t\t\t",SGMLatom(size 0),"\n\t\t
      \t",SGMLatom(size 7),"\n"}),1)                                            
                             
  t.pike:37: /main()->walk(({"\n\t",SGMLatom(size 9),"\n\n\t\t\n"}),1)
  t.pike:37: /main()->walk(({"\n\t",SGMLatom(size 2),"\n",SGMLatom(size 3)}),1)
  t.pike:37: /main()->walk(({"\n",SGMLatom(size 4),"\n"}),UNDEFINED)
  t.pike:37: /main()->walk(({SGMLatom(size 3)}),UNDEFINED)
  t.pike:42:
      /main()->get_main_str2("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\" \"http://www.w3
      .org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html
xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"i
      a\" lang=\"ia\" dir=\"lt"+[522986])                                       
                             
  t.pike:47: /main()->main()