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

Prevent segfault when refitting item in spillable container #75687

Conversation

inogenous
Copy link
Contributor

Summary

Bugfixes "Prevent segfault when refitting item in spillable container"

Purpose of change

Prevents segfault from accessing an invalidated item_location when refitting an item that was stored inside a spillable container. Fixes #74254 .

Describe the solution

The previous segfault could be reproduced by having an inventory like:

backpack >
  aluminum can >
    work t-shirt (poor fit)

And then using a tailor's kit to refit the t-shirt caused a segfault. Part of refitting will invalidate items inside the aluminum can, which is a spillable container, and dereferencing the tshirt after having repaired it will segfault.

This change instead makes sure that we do not use fix_location after we have called repair_item_actor::repair. It also adds a unit test that reproduced the previous segfault (but works on this branch).

Describe alternatives you've considered

Testing

Can no longer reproduce the segfault in #74254 . All of the work clothing items can now be repaired:

snapshot2

Additional context

It's odd that we were able to put the tshirt in the can in the first place, since it's a spillable container, and that should not be possible in a backpack. But that's for a different issue.

@inogenous inogenous force-pushed the segfault-repair-item-in-spillable-container branch from 2105aad to 3823088 Compare August 15, 2024 07:45
@github-actions github-actions bot added <Bugfix> This is a fix for a bug (or closes open issue) Code: Tests Measurement, self-control, statistics, balancing. [C++] Changes (can be) made in C++. Previously named `Code` astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Aug 15, 2024
Prevents segfault from accessing an invalidated `item_location` when
refitting an item that was stored inside a spillable container.

The previous segfault could be reproduced by having an inventory like:
```
backpack >
  aluminum can >
    work t-shirt (poor fit)
```
And then using a tailor's kit to refit the t-shirt caused a segfault.
Part of refitting will invalidate items inside the aluminum can, which
is a spillable container, and dereferencing the tshirt wil segfault.

This change instead makes sure that we do not use `fix_location` after
we have called `repair_item_actor::repair`. It also adds a unit test
that reproduced the previous segfault (but works on this branch).
@inogenous inogenous force-pushed the segfault-repair-item-in-spillable-container branch from 3823088 to 7d59354 Compare August 15, 2024 09:27
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Aug 15, 2024
@Maleclypse Maleclypse merged commit 99472fc into CleverRaven:master Aug 16, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

repairing clothing segfault
2 participants