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

RegisterRawNuiCallback Crash #2783

Open
someone005 opened this issue Sep 10, 2024 · 4 comments
Open

RegisterRawNuiCallback Crash #2783

someone005 opened this issue Sep 10, 2024 · 4 comments
Labels
bug crash triage Needs a preliminary assessment to determine the urgency and required action

Comments

@someone005
Copy link
Contributor

someone005 commented Sep 10, 2024

What happened?

I discovered that if you pass empty string to callback function, it will cause game crash.

Video

LUA Code:

RegisterRawNuiCallback('exampleCallback', function(rawData, cb)
    cb('')
end)

NUI JS Code

fetch(`https://${GetParentResourceName()}/exampleCallback`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json; charset=UTF-8',
    },
    body: ""
}).catch(err => {})

Expected result

Callback data should be properly packed

Reproduction steps

  1. Create resource with client lua script (description code) and JS Code implemented in script's NUI
  2. Start the resource

Importancy

Crash

Area(s)

Natives

Specific version(s)

FiveM: 9837 Server: 9481 Windows

Additional information

No response

@someone005 someone005 added bug triage Needs a preliminary assessment to determine the urgency and required action labels Sep 10, 2024
@github-actions github-actions bot added the crash label Sep 10, 2024
@AvarianKnight
Copy link
Contributor

It should be noted that this will happen if you return any invalid data during any of this, this entire section expects the end user to never send any invalid data via the callback.

@someone005
Copy link
Contributor Author

Yeah, it should noted, but there's one thing. Why the same data passed to RegisterNUICallback cb function doesn't crash the game?

@AvarianKnight
Copy link
Contributor

This is a "raw callback" you're expected to return an empty table if you don't want to return anything, or a table with this kind of structure

struct RequestCallback {
	// optional, doesn't have to be set
	// headers to set for the call back
	Array<(string, string)> headers;

	// alternate to returning an array
	IDictionary<string, string> headers;

	// optional, doesn't have to be set
	// the status code 
	int status;

	// optional, doesn't have to be set
	// the data to return
	string body;
}

@AvarianKnight
Copy link
Contributor

Here's a patch patch I wrote up yesterday, though its not the cleanest, nor is it tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug crash triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
Development

No branches or pull requests

2 participants