Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(msgpack): JSON map conversion error-handling #2825

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tens0rfl0w
Copy link
Contributor

Goal of this PR

Lua (unlike JS) does not convert table indices to String, which can result in table indices being of various types. Instead of throwing an unhandled exception, we now handle invalid-data more gracefully.

How is this PR achieving the goal

This change mimics the msgpack-c example impl. of map -> JSON conversion with added checks and verbose console errors.

Handling for the following cases has been added:

  • Out-ouf-bounds exception when key type is int
  • Duplicate key check (when converting from int->string)
  • Invalid type as key -> type ≠ string, int, binary

On error, the map object will get nullified to avoid partial data.
While not every case necessarily needs to throw an error, this was done to avoid 'wrong' user-data staying unnoticed.

Different key types (string, int) in the same map are also now supported.

This PR applies to the following area(s)

FiveM

Successfully tested on

Game builds: Not applicable

Platforms: Windows (Client)

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

/

@github-actions github-actions bot added the invalid Requires changes before it's considered valid and can be (re)triaged label Oct 1, 2024
@tens0rfl0w tens0rfl0w force-pushed the fix/msgpack-json-map-error-handling branch 2 times, most recently from 6899a4f to d9188fa Compare October 3, 2024 12:22
This fixes various unhandled exceptions when trying to convert a msgpack map object to a JSON object:
- Out-ouf-bounds exception handling when key type is int
- Duplicate key check (when converting from int->string)
- Invalid type as key -> type ≠ string, int, bin
@tens0rfl0w tens0rfl0w force-pushed the fix/msgpack-json-map-error-handling branch from d9188fa to e134121 Compare October 5, 2024 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Requires changes before it's considered valid and can be (re)triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants