Skip to content

Fix buffers being copied by reference in deep copies - #22

Open
tktj12 wants to merge 1 commit into
MadStudioRoblox:mainfrom
tktj12:patch-1
Open

Fix buffers being copied by reference in deep copies#22
tktj12 wants to merge 1 commit into
MadStudioRoblox:mainfrom
tktj12:patch-1

Conversation

@tktj12

@tktj12 tktj12 commented Aug 2, 2026

Copy link
Copy Markdown

Problem

DeepCopyTable() and ReconcileTable() copy buffers by reference.
So the module-level template itself gets mutated.

Since JSONAcceptable (line ~970) explicitly lists buffer as a valid
profile data type, and the template is documented as a "hard-copy"
(line ~44), buffers should be hard-copied

Repro

local TEMPLATE = { Bits = buffer.create(4) }
local Store = ProfileStore.New("BufferRepro", TEMPLATE)

local a = Store.Mock:StartSessionAsync("playerA")
local b = Store.Mock:StartSessionAsync("playerB")

print(a.Data.Bits == b.Data.Bits)        --> true  (expected false)

buffer.writeu32(a.Data.Bits, 0, 123)
print(buffer.readu32(b.Data.Bits, 0))    --> 123   (expected 0)
print(buffer.readu32(TEMPLATE.Bits, 0))  --> 123   -- template is mutated

The template corruption persists for the whole server session.

Affected call sites

  • MissingProfileHandle — every new profile shares the template's buffer
  • Profile.New — LastSavedData aliases the live buffer
  • MockUpdateAsync — mock store aliases live buffers, so Studio and production behave differently
  • ReconcileTable — same issue when filling in a missing buffer key

Fix

Adds a CopyBuffer helper and a buffer branch to both copy functions.

Note: the trailing-newline change at EOF was added automatically by the
GitHub web editor and is not part of the fix.

DeepCopyTable() and ReconcileTable() copied buffer values by reference, so a buffer in the profile template was shared by every new profile and the template itself could be mutated at runtime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant