Anaminus / roblox-bug-tracker

Formerly an unofficial bug tracker for Roblox.
31 stars 24 forks source link

Table marshalling duplicates objects that are referred to by multiple tables #255

Open Quenty opened 10 years ago

Quenty commented 10 years ago

ROBLOX's parser for remote functions and the DataStore cannot handle multiple pointers to the same object.

Repro

Run this on the server:

Instance.new("RemoteEvent", Workspace)

image

Run this on the client

local RE = Workspace:FindFirstChild("RemoteEvent")
RE.OnClientEvent:connect(function(X) for _, Item in pairs(X) do print(Item.Links[1]) end end)

image

Run this on the server:

local Link = {}
local DB = {{Name = "ItemA"; Links = {Link};};{Name = "ItemB"; Links = {Link};}}; 
local RE = Workspace.RemoteEvent RE:FireClient(game.Players.Player1, DB)

image

The code above creates a new RemoteEvent in Workspace, and connects an event on the client. ROBLOX's parser cannot handle the pointers and crashes ROBLOX studio (the client).

It creates two tables instead of pointing to the same one.

A slight modification to this code will create a crash.

local Link = {}
local DB = {{Name = "ItemA"; Links = {Link};};{Name = "ItemB"; Links = {Link};}}; 
DB[3] = {Name="ItemC";Links={DB[1]};};
local RE = Workspace.RemoteEvent RE:FireClient(game.Players.Player1, DB)

Which will actually make ROBLOX crash. This issue https://github.com/Anaminus/roblox-bug-tracker/issues/132 dealt with this, but apparently it has come back.

matthewdean commented 10 years ago

@Quenty That tables with cycles crash ROBLOX's data serializer is already covered by #132. Please remove it from this issue.

Here is a much simpler reproduction case for this issue. As you can see, the tables have two separate memory locations even though they were the same table to begin with. This behavior may be because the tables are always cloned so that modification of the original table is prevented.

local bindableFunction = Instance.new("BindableFunction")
bindableFunction.OnInvoke = function()
  local t = {}
  return t, t
end
print(bindableFunction:Invoke())
--> table: 0C5D3698 table: 0C5D36C8