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(common): fix memory corruption for dynamic to static array conversion #1598

Merged
merged 4 commits into from
Sep 25, 2023

Conversation

dk1a
Copy link
Contributor

@dk1a dk1a commented Sep 24, 2023

fixes #1005

@changeset-bot
Copy link

changeset-bot bot commented Sep 24, 2023

🦋 Changeset detected

Latest commit: 360be09

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@latticexyz/cli Patch
@latticexyz/common Patch
@latticexyz/block-logs-stream Patch
@latticexyz/config Patch
@latticexyz/dev-tools Patch
@latticexyz/protocol-parser Patch
@latticexyz/store-indexer Patch
@latticexyz/store-sync Patch
@latticexyz/store Patch
@latticexyz/world-modules Patch
@latticexyz/world Patch
@latticexyz/react Patch
@latticexyz/abi-ts Patch
create-mud Patch
@latticexyz/ecs-browser Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/network Patch
@latticexyz/noise Patch
@latticexyz/phaserx Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
@latticexyz/services Patch
@latticexyz/solecs Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/std-client Patch
@latticexyz/std-contracts Patch
@latticexyz/store-cache Patch
@latticexyz/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dk1a dk1a marked this pull request as ready for review September 24, 2023 19:47
@dk1a dk1a requested review from alvrs and holic as code owners September 24, 2023 19:47
// (without the length check this could lead to memory corruption)
assembly {
_result := add(_value, 0x20)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any way we can add a regression test for this to make sure we don't run into this in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory corruption tests are tricky, I think I'm too sleepy to write 1 rn, we can add an issue for later, tests aren't production code so does freeze affect em?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can always add more tests later! planning to do extend the test suite in general next week

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added here: #1603

_result := add(_value, 0x20)
if (_value.length < 1) {
// ignore invalid dynamic arrays that are too small
return _result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is invalid, should this revert instead of returning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a 0-length array is kinda valid (it's uninitialized), so maybe I should change the comment?
and other cases are weird and shouldn't happen, but it's cheaper to return empty than add more checks

@alvrs alvrs merged commit c4f4924 into main Sep 25, 2023
@alvrs alvrs deleted the dk1a/fix-memory-corruption branch September 25, 2023 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible array to static array memory corruption
3 participants