oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
|
| 21 Aug 2014 02:01 AM |
The challenge is to cause the stack overflow error without creating any function. Should work in both Rbx.Lua and pure Lua 5.1.
It's an open-ended challenge, means their can be more than one solution. Obviously the solutions are not straightforward. Getting any one of the solutions considers you as a winner. Their can be more than one winner.
Common thoughts: 1- 'loadstring' does create a new function, so you can't use that to solve the challenge. 2- Please don't do error("omg stack overflow error, i win k") They're silly and not a solution.
I believe there's only 2 solutions for this (that's how many I could find), but I might be wrong.
Gl!
|
|
|
| Report Abuse |
|
|
|
| 21 Aug 2014 02:33 AM |
Does using metatables count as creating a function?
Because if not:
local t = {} setmetatable(t ,{ __newindex = function(tab, ind, val) tab[ind] = val end })
t["cookie"] = "nom"
Do I get a cookie? |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
|
| 21 Aug 2014 02:44 AM |
" function(tab, ind, val) tab[ind] = val end"
You just created a function there ^ |
|
|
| Report Abuse |
|
|
|
| 21 Aug 2014 08:19 AM |
function StackOverflow() StackOverflow() end StackOverflow() |
|
|
| Report Abuse |
|
|
|
| 21 Aug 2014 08:20 AM |
Because why can't I create functions? :(
If you insist, I could do this?
loadstring(script.StringValue.Value)()
And have the exact same code in the string value. |
|
|
| Report Abuse |
|
|
|
| 21 Aug 2014 08:24 AM |
| Clearly I'm not using my brain. |
|
|
| Report Abuse |
|
|
lah30303
|
  |
| Joined: 15 Feb 2008 |
| Total Posts: 10027 |
|
|
| 21 Aug 2014 09:41 AM |
| Would it count if I created my own stack with metatables and overflowed it? It might not say the same error, but I'm technically overflowing a stack. |
|
|
| Report Abuse |
|
|
bohdan77
|
  |
| Joined: 10 Aug 2008 |
| Total Posts: 7944 |
|
|
| 21 Aug 2014 10:08 AM |
print(string.find(string.rep("a", 2^20), string.rep(".?", 2^20))) ---Causes a C-Stack overflow.
|
|
|
| Report Abuse |
|
|
bohdan77
|
  |
| Joined: 10 Aug 2008 |
| Total Posts: 7944 |
|
|
| 21 Aug 2014 10:23 AM |
setfenv(1, getfenv(1))()
does that count? |
|
|
| Report Abuse |
|
|
mathchamp
|
  |
| Joined: 22 Oct 2007 |
| Total Posts: 320 |
|
|
| 21 Aug 2014 10:47 AM |
This will overflow the C stack, by abusing a built-in function, resulting in infinite recursion:
t = {} t[1] = table.sort t[2] = t
table.sort(t,table.sort)
It will try to sort the table t, but the comparison function is... table.sort! And what does table.sort pass to the comparison function? Two entries of the table. One entry is the table itself, the other is the function table.sort. Thus table.sort will attempt to compare t and table.sort using table.sort as a comparison function.
Thus table.sort(t,table.sort) will call table.sort(t,table.sort) in an attempt to sort the table. Obviously, this is an infinite recursion and the stack overflows. |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 21 Aug 2014 12:47 PM |
print(string.find(string.rep("a", 2^20), string.rep(".?", 2^20)))
Good ol' stack overflow bug in 5.1's pattern matching API. In versions greater than 5.2 this gives an error: 'Pattern too complex' |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
|
| 21 Aug 2014 05:02 PM |
@Bohan
"setfenv(1, getfenv(1))()"
Yup, you're not creating any new function with this. 'setfenv' returns the environment of the given level/func you put. And the func of the current environment already exists from the start.
@mathcamp
"t = {} t[1] = table.sort t[2] = t
table.sort(t,table.sort)""
This is really nice, didn't think of it. And you pretty much explained it well :) It seems there's more than two solutions now. The challenge is getting more interesting and harder.
@digpoe,bohan
"print(string.find(string.rep("a", 2^20), string.rep(".?", 2^20)))"
Not getting a stack overflow error, getting a "Segmentation fault" in Lua 5.1 and server crashes in Rbx.Lua lol. |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
|
| 21 Aug 2014 05:06 PM |
So we far we have two winners: 1- bohdan77 (1 solution) 2- mathchamp (1 solution) |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
|
| 21 Aug 2014 05:09 PM |
| *'setfenv' returns the function of the given environment level/function you put* |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Aug 2014 07:22 PM |
Common thoughts: 1- 'loadstring' does create a new function, so you can't use that to solve the challenge. 2- Please don't do error("omg stack overflow error, i win k") They're silly and not a solution. |
|
|
| Report Abuse |
|
|
utabon
|
  |
| Joined: 12 Aug 2009 |
| Total Posts: 900 |
|
|
| 22 Aug 2014 01:24 AM |
| Its funny because I understand nothing you guys are talking about lol. |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 22 Aug 2014 05:48 AM |
@oxcool
try it in a C#-based interpreter or something then ;) |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
|
| 22 Aug 2014 06:22 PM |
@digpoe
It should work in Rbx.Lua as well. |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 22 Aug 2014 08:00 PM |
| I was about to post what bohdan said but he beat me to it. ): |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 22 Aug 2014 09:00 PM |
I just ran this code for a quick test:
local function r(x) print(x) r(x+1) end r(1)
And I got to: 16380
So I'm (guessing) that if I do this:
do do do do do do ...
16381 times, and then do this:
end end end end end ...
16381 times, I can create a stack overflow.
|
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
|
| 22 Aug 2014 09:14 PM |
@Quenty
Except do/if-statement does not make a stack. They do make a scope though like functions, but not a stack. |
|
|
| Report Abuse |
|
|
| |
|
|
| 23 Aug 2014 12:36 AM |
| edit; just read the "must work in both yada yada". That's a dumb requirement. Mine works in Lua 5.1. |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
|
| 23 Aug 2014 01:11 AM |
| This is part of the challenge :) You can't use debug/os stuff or roblox instance stuff since it much work on both. |
|
|
| Report Abuse |
|
|