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 crash when component parameters are invalid #16735

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

purplg
Copy link
Contributor

@purplg purplg commented Dec 10, 2024

Objective

Fix the following crash when using BRP to insert a malformed component:

thread 'main' panicked at /home/purplg/workspaces/evtc-replay/bevy/crates/bevy_remote/src/builtin_methods.rs:926:18:
called `Result::unwrap()` on an `Err` value: Error("invalid type: map, expected f32", line: 0, column: 0)

Solution

Return an error instead of unwrapping.

Testing

Tested by sending this malformed payload before and after implementing the fix:

{
    "jsonrpc": "2.0",
    "id": 0,
    "method": "bevy/insert",
    "params": {
        "entity": 4294967307,
        "components": {
            "bevy_transform::components::transform::Transform": {
                "rotation": [
                    0.0,
                    0.0,
                    0.0,
                    1.0
                ],
                "scale": [
                    1.0,
                    1.0,
                    1.0
                ],
                "translation": [
                    {},
                    0.0,
                    0.0
                ]
            }
        }
    }
}

After implementing the fix, I receive the following response instead of a crash:

{
    "jsonrpc": "2.0",
    "id": 0,
    "error": {
        "code": -23402,
        "message": "bevy_transform::components::transform::Transform is invalid: invalid type: map, expected f32"
    }
}

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added P-Crash A sudden unexpected crash A-Dev-Tools Tools used to debug Bevy applications. S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 10, 2024
@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 10, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 10, 2024
Merged via the queue into bevyengine:main with commit 7662b4f Dec 10, 2024
34 checks passed
BD103 pushed a commit to BD103/bevy that referenced this pull request Dec 10, 2024
# Objective

Fix the following crash when using BRP to insert a malformed component:

```
thread 'main' panicked at /home/purplg/workspaces/evtc-replay/bevy/crates/bevy_remote/src/builtin_methods.rs:926:18:
called `Result::unwrap()` on an `Err` value: Error("invalid type: map, expected f32", line: 0, column: 0)
```

## Solution

Return an error instead of unwrapping.

## Testing

Tested by sending this malformed payload before and after implementing
the fix:

```json
{
    "jsonrpc": "2.0",
    "id": 0,
    "method": "bevy/insert",
    "params": {
        "entity": 4294967307,
        "components": {
            "bevy_transform::components::transform::Transform": {
                "rotation": [
                    0.0,
                    0.0,
                    0.0,
                    1.0
                ],
                "scale": [
                    1.0,
                    1.0,
                    1.0
                ],
                "translation": [
                    {},
                    0.0,
                    0.0
                ]
            }
        }
    }
}
```

After implementing the fix, I receive the following response instead of
a crash:

```json
{
    "jsonrpc": "2.0",
    "id": 0,
    "error": {
        "code": -23402,
        "message": "bevy_transform::components::transform::Transform is invalid: invalid type: map, expected f32"
    }
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Dev-Tools Tools used to debug Bevy applications. D-Trivial Nice and easy! A great choice to get started with Bevy P-Crash A sudden unexpected crash S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants