Skip to content

fix(scripting/v8): handle Proxy objects in msgpack serialization#3852

Open
gtolontop wants to merge 1 commit intocitizenfx:masterfrom
gtolontop:fix/msgpack-proxy-serialization
Open

fix(scripting/v8): handle Proxy objects in msgpack serialization#3852
gtolontop wants to merge 1 commit intocitizenfx:masterfrom
gtolontop:fix/msgpack-proxy-serialization

Conversation

@gtolontop
Copy link

@gtolontop gtolontop commented Mar 8, 2026

Goal of this PR

Fix the TypeError: r.toArray is not a function crash that occurs when passing Proxy objects to msgpack serialization (e.g. via emitNet).

How is this PR achieving the goal

Adds a materialize() fallback in the pack() function that deep-clones Proxy objects into plain objects/arrays before encoding. The fallback only triggers on TypeError, so there is zero performance impact on the normal path.

  1. pack() first tries the normal msgpack.encode
  2. If it throws a TypeError (the specific error Proxies cause), it retries with materialize(data) which recursively converts Proxies to plain objects
  3. materialize handles circular references via WeakMap and preserves ArrayBuffer/TypedArray

This PR applies to the following area(s)

FiveM, RedM (shared V8 scripting runtime)

Successfully tested on

  • emitNet with a Proxy object as parameter — serializes without crash
  • emitNet with plain objects — works as before, no fallback triggered
  • Nested Proxy objects — serialize correctly
  • console.warn is emitted when fallback activates

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

Fixes #3824

@github-actions github-actions bot added the triage Needs a preliminary assessment to determine the urgency and required action label Mar 8, 2026
@gtolontop gtolontop changed the title Fix msgpack Proxy serialization crash fix(scripting/v8): handle Proxy objects in msgpack serialization Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage Needs a preliminary assessment to determine the urgency and required action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V8's msgpack doesn't handle proxies?

1 participant