fix(scripting/v8): handle Proxy objects in msgpack serialization#3852
Open
gtolontop wants to merge 1 commit intocitizenfx:masterfrom
Open
fix(scripting/v8): handle Proxy objects in msgpack serialization#3852gtolontop wants to merge 1 commit intocitizenfx:masterfrom
gtolontop wants to merge 1 commit intocitizenfx:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal of this PR
Fix the
TypeError: r.toArray is not a functioncrash that occurs when passing Proxy objects to msgpack serialization (e.g. viaemitNet).How is this PR achieving the goal
Adds a
materialize()fallback in thepack()function that deep-clones Proxy objects into plain objects/arrays before encoding. The fallback only triggers onTypeError, so there is zero performance impact on the normal path.pack()first tries the normalmsgpack.encodeTypeError(the specific error Proxies cause), it retries withmaterialize(data)which recursively converts Proxies to plain objectsmaterializehandles circular references viaWeakMapand preservesArrayBuffer/TypedArrayThis PR applies to the following area(s)
FiveM, RedM (shared V8 scripting runtime)
Successfully tested on
emitNetwith a Proxy object as parameter — serializes without crashemitNetwith plain objects — works as before, no fallback triggeredconsole.warnis emitted when fallback activatesChecklist
Fixes issues
Fixes #3824