I just accidentally found a literal zip bomb for the ram in love

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
alejandroalzate
Citizen
Posts: 67
Joined: Sat May 08, 2021 9:45 pm

I just accidentally found a literal zip bomb for the ram in love

Post by alejandroalzate »

Hey guys with little boilerplate i'll go directly to the "Thing",
so i trying to develop a game and one of the features is video on the level's background, i was implementing the logic of pause menu (You can roast me btw):

Code: Select all

local function advanceTime(dt)
	if type("mediaContent") then
		local success, res = pcall(mediaContent.tell, mediaContent)
		if success then
			elapsedTime = res or 0
		else
			print(res)
		end
		--What i added, that caused the mayhem
		if type(menu) == "table" then
			if menu.show then
				waveSource:pause()
				mediaContent:pause()
			else
				mediaContent:play()
				waveSource:play()
			end
		end
	end
end
The supposed logic goal was that whenever the pause menu was on screen well is supposed to be a pause menu right? so we pause the video and resume after, my oversight was that once you unpaused, the thing will just spam the hell outta

Code: Select all

play()
, and i kid you not it just needed 3 seconds to fill my entire ram (8gb 7.9 usable - 2gb used by the system), apparently when called repeadtedly the play() method generates a lot of garbage i do not treat it as a bug since i'm supposed to call it once. but i thought that was worth the share of that oversight of mine.

Also the fix was dirty cheap for those wondering (roast allowed again):

Code: Select all

local function advanceTime(dt)
	if type("mediaContent") then
		local success, res = pcall(mediaContent.tell, mediaContent)
		if success then
			elapsedTime = res or 0
		else
			print(res)
		end
		if type(menu) == "table" then
			if menu.show then
				waveSource:pause()
				mediaContent:pause()
			else
				if mediaContent:tell() > 0 and not mediaContent:isPlaying() then
					mediaContent:play()
					waveSource:play()
				end
			end
		end
	end
end
But i'm also considering adding the check when paused as well just to play it safe

Code: Select all

target = boardIndex.getWhosPeekingThisLine()
target:setObey(true)
MrFariator
Party member
Posts: 513
Joined: Wed Oct 05, 2016 11:53 am

Re: I just accidentally found a literal zip bomb for the ram in love

Post by MrFariator »

While it's surprising that your example creates so much garbage, it's not also not particularly special, now is it? There are many ways to fill up RAM (excessive table creation, loading a bunch of assets into memory), force heavy CPU loads (just modifying love.run slightly could do), or cause excessive I/O operations (writing/deleting a bunch of files with love.filesystem), purposefully or otherwise, that in theory the set of LÖVE API functions that don't cause issues if used inappropriately is probably much smaller than the inverse.

At the end of the day, whenever you download something off the internet you kind of have to trust that the thing you grabbed isn't malicious.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: I just accidentally found a literal zip bomb for the ram in love

Post by zorg »

Technically, calling play on audio Sources while they are already playing should not do anything, so i'm really suprised if that would actually be the issue here and not something else you're also doing that you didn't share (e.g. calling :clone on one of the sources repeatedly; that *might* fill up memory if this happens tons of times every time update is called.)
Not sure about videos if that's what mediaContent is.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
slime
Solid Snayke
Posts: 3133
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: I just accidentally found a literal zip bomb for the ram in love

Post by slime »

There's at least one third party audio source wrapper library (SLAM) which overwrites Source:play to create a new Source each time it's called. If you're using that it'd cause huge memory increases when you call Source:play every frame.

Otherwise zorg is correct.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 59 guests