fix(store): prevent delete out of bounds in spliceDynamicData - #3521
Merged
Conversation
|
alvrs
force-pushed
the
splice-dynamic-data-patch
branch
from
February 7, 2025 14:03
3b20599 to
10bbab5
Compare
alvrs
force-pushed
the
splice-dynamic-data-patch
branch
from
March 17, 2025 19:54
10bbab5 to
3ff178f
Compare
alvrs
force-pushed
the
splice-dynamic-data-patch
branch
from
March 17, 2025 21:10
3ff178f to
5027f3e
Compare
alvrs
marked this pull request as ready for review
March 17, 2025 22:15
Member
Author
|
combining all changes that require an audit into #3630 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
spliceDynamicData, we’re checking thatstartis within the bounds of the previous field length but aren’t consideringdeleteCountin that check. There is another check that checks thatstart + deleteCountlines up with the previous length of the field if the total length of the field changed, but this only applies if the length changed. That means if the length of the data to insert is the same asdeleteCount, it is possible to “insert data after the length of the field” (ie by settingstartto the end of the field). I put “insert data after the length of the field” in quotes, since the length of the field is not actually changed, which means when retrieving the whole field onchain the data appended at the end would not be included, similar to how items that are pop’ed from a dynamic field are not actually cleared from storage but just the field length is reduced.But means indexers/clients need to be aware of this nuance and use
encodedLengthsas source of truth (like we do onchain).We can remove this edge case by changing the check to
if(startWithinField > previousFieldLength - deleteCount).When using our table libraries this does not happen since they don't call
spliceDynamicDatawith an invalidstartvalue, but it’s possible to trigger this by callingworld.spliceDynamicDatamanually.