-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Heap data corruption in scripts #4828
Comments
The specification says that
The VM follows the spec here. We could change the spec and not restore Instead maybe the compiler could handle the memory being unwritable and also avoid allocating over it with |
This gets needlessly complex if we have multiple objects on the heap, and with some of them pointing internally to the others. I vote against this. The whole point of a heap is for it to be independent of the stack. A dealloc instruction may help, but without an actual runtime to manage and reallocate deallocated memory it isn't that useful. This is equal to having a |
Agreed. The only way forwards without a big redesign is not restoring Spec PR: FuelLabs/fuel-specs#506 |
Causes this issue FuelLabs/sway#4828
Fixed in FuelLabs/fuel-vm#525. Should we keep this open while waiting for the fix to propagate through fuel-vm and fuel-core releases? |
Yes, let it be open until confirmation. |
Assigning back to @segfault-magnet to verify and close. |
While working on 1046 @hal3e and I noticed that vectors allocated and returned from a contract call have their data located below the current value of
hp
.The heap is expanded during the contract call but the expansion is reverted after the call is finished.
This
hp
revert leaves the returned vector data in unallocated memory. If you allocate enough bytes and write to them you will overwrite the returned vector's data.A minimal example can be seen here: https://github.com/segfault-magnet/sway_heap_issue, running
doit.sh
will spin a node, deploy the contract and replace theCONTRACT_ID
placeholder with the actual contract id and proceed to run the script.Tested on:
❯ forc --version forc 0.42.1 ~ ❯ fuel-core --version fuel-core 0.18.3
The text was updated successfully, but these errors were encountered: