From 71b27ee4ca6b29f735969ff3b7daf981741c3c78 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Wed, 1 Nov 2023 14:19:10 +0100 Subject: [PATCH] Set capacity to length before storing value So I think we can state that the bugs we have in #960, #1167 and #1170, are all related to slice storage when its capacity is different than its length. @deelawn found a great way to overcome that bug, but the bug is still there, somewhere in the VM code I think. I spent the last couple of days trying to find it, unfortunately without success. That said, I found a workaround, that could be also applied: when a slice is stored, ignore any capacity different than the slice's length. I think this is a good workaround because its one-line and because we don't really care about storing slice with capacity higher than their length (unless I'm missing something). --- gnovm/pkg/gnolang/realm.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 5f6a532cbc0..5090bb510f3 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -1127,7 +1127,9 @@ func copyValueWithRefs(parent Object, val Value) Value { Base: toRefValue(parent, cv.Base), Offset: cv.Offset, Length: cv.Length, - Maxcap: cv.Maxcap, + // Force capacity to length, because we have issues with store when they + // are differents. + Maxcap: cv.Length, } case *StructValue: fields := make([]TypedValue, len(cv.Fields))