-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix: wrong reference count after invalid Map[key] = value
#4027
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3693, please...
IIUC correctly bytecode triggering this will make VM fail, so the exact count is not much relevant in this case. But worth fixing anyway.
| } | ||
| } | ||
|
|
||
| foreach (var item in _array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't use the same foreach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't use the same foreach?
For example:
The _array has 2 items, and the first added, but the second is invalid.
Line 86 throws a InvalidOperationException, and then the ReferenceCounter is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't use the same foreach?
This issue shouldn't be triggered in real environments, but it’s better to be cautious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If throw an exceptiotge execution is halted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If throw an exceptiotge execution is halted
Make it more rigorous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If throw an exceptiotge execution is halted
Make it more rigorous.
Slower without need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If throw an exceptiotge execution is halted
Make it more rigorous.
Slower without need
It's so trivial.
Few items in array in most cases.
And after the first foreach, the code will be hot(cache and branch predictor), it should be fast enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need, it will be a fault, have no sense
Description
When set a value to map, The old value reference removed in
Line 55or the new key reference added inLine 57.But if
Line 60throws aInvalidOperationException, the reference count will be wrong,because the
ReferenceCounterhas been updated, but the internal collection not.neo/src/Neo.VM/Types/Map.cs
Lines 52 to 62 in 6c7f6c4
Type of change
Checklist: