String too long - Trying to edit source of script


#1

Describe the bug

When trying to edit the source of a script via a plugin, it errors with “String too long”

image

Reproduction: (A plugin script)

local s = string.rep("OOF", 100000)

local thing = Instance.new("Script", workspace)
thing.Source = s

Why is this a problematic bug?

Currently developing a git integration plugin, and it requires modifying the source of the scripts to change to newer versions, and prepend git related data at the top of the script, and phantom forces has really large singular scripts, which this bug conflicts with.

The length of the script I am trying to modify has a string length of 300,000+ characters, and it seems the limit is about 200,000.


#2

I’ve actually run into this issue before while trying to obfuscate or otherwise manipulate the source of a script, and having the limit raised would be helpful for my purposes. That being said, some testing shows me that 199,999 is a hard limit in all string properties.

I ran this code to test the max length of strings:

Be wary of running this because it’s going to take a long time because it’s not meant for speed.

local Script = Instance.new("Script")
local rep = string.rep
local pcall = pcall

local function Set(i)
	Script.Source = rep("-", i)
end

for i = 1, 2^32 do
	if not pcall(Set, i) then
		print(i-1) -- To get an accurate value
		break
	end
end

And got:

199999

I did the same thing but with the Value property of a StringValue and got:

199999

With the name of a StringValue:

199999

This makes me think this is an intentional limit and not a bug, but regardless it should be raised.


#3

The limit has been 200k for many months now. It’s a problem for my obfuscation and my place statistics parser too. I just have to work around it and create a new script instances and stitch it together by hand.


#4

I’ve looked into it in my own time, when you set the string of a script it makes it into a “ProtectedString” in the instance bridge of roblox. but in that process it calls “throwable_lua_tostring” a C function in the engine with a hardcoded size limit, which it seems that function was made for a past issue dealing with networking limitations.
That issue seems like it is no longer a issue that applies to the “ProtectedString” though, due to the fact they don’t send the source anymore. Instead they just send the bytecode rather then replicating the whole protected string.
I’d imagine using define macros it can be made a exception for studio for setting a “ProtectedString” on a script or just rather remove this functionality for setting a “ProtectedString” via lua in the end.


#5

These network limitations may still apply in team create, but I’m pretty sure you can still paste strings longer than 200k (you just can’t manually set .Source from a script). I’ve worked on many projects that involve processing lots of data or auto-generating source, and this limitation is always frustrating.


#6

Good point, I disassembled the latest roblox version regarding serializing these strings rather then going off of old stuff. The actively used max payload size per a string can be found in the client flags. which is currently 96000000 bytes, judging by the size I think they overcame this limitation. But if they didn’t it would be nice to make the limit more reasonably higher with the current max payload size.