Skip to content

Commit 43373ba

Browse files
authored
Merge pull request #1994 from onetechnical/onetechnical/relbeta2.5.2
go-algorand 2.5.2-beta
2 parents aa02b68 + 4019275 commit 43373ba

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

buildnumber.dat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1
1+
2

data/transactions/logic/eval.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1924,11 +1924,14 @@ func opSetBit(cx *evalContext) {
19241924
// we're thinking of the bits in the byte itself as
19251925
// being big endian. So this looks "reversed"
19261926
mask := byte(0x80) >> bitIdx
1927+
// Copy to avoid modifying shared slice
1928+
scratch := append([]byte(nil), target.Bytes...)
19271929
if bit == uint64(1) {
1928-
target.Bytes[byteIdx] |= mask
1930+
scratch[byteIdx] |= mask
19291931
} else {
1930-
target.Bytes[byteIdx] &^= mask
1932+
scratch[byteIdx] &^= mask
19311933
}
1934+
cx.stack[pprev].Bytes = scratch
19321935
}
19331936
cx.stack = cx.stack[:prev]
19341937
}
@@ -1961,6 +1964,8 @@ func opSetByte(cx *evalContext) {
19611964
cx.err = errors.New("setbyte index > byte length")
19621965
return
19631966
}
1967+
// Copy to avoid modifying shared slice
1968+
cx.stack[pprev].Bytes = append([]byte(nil), cx.stack[pprev].Bytes...)
19641969
cx.stack[pprev].Bytes[cx.stack[prev].Uint] = byte(cx.stack[last].Uint)
19651970
cx.stack = cx.stack[:prev]
19661971
}

data/transactions/logic/eval_test.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,14 @@ func TestBits(t *testing.T) {
39003900
testAccepts(t, "byte 0x0000; int 15; int 1; setbit; byte 0x0001; ==", 3)
39013901
testAccepts(t, "int 0x0000; int 3; int 1; setbit; int 0x0008; ==", 3)
39023902
testAccepts(t, "int 0x0000; int 12; int 1; setbit; int 0x1000; ==", 3)
3903+
3904+
// These test that setbyte is not modifying a shared value.
3905+
// Since neither bytec nor dup copies, the first test is
3906+
// insufficient, the setbit changes the original constant (if
3907+
// it fails to copy).
3908+
testAccepts(t, "byte 0xfffff0; dup; int 21; int 1; setbit; byte 0xfffff4; ==; pop; byte 0xfffff0; ==", 3)
3909+
testAccepts(t, "byte 0xffff; byte 0xf0; concat; dup; int 21; int 1; setbit; byte 0xfffff4; ==; pop; byte 0xfffff0; ==", 3)
3910+
39033911
}
39043912

39053913
func TestBytes(t *testing.T) {
@@ -3914,8 +3922,13 @@ func TestBytes(t *testing.T) {
39143922
testPanics(t, `byte "john"; int 4; getbyte; int 1; ==`, 3) // past end
39153923

39163924
testAccepts(t, `byte "john"; int 2; int 105; setbyte; byte "join"; ==`, 3)
3917-
// dup makes copies, modifying one does not change the other
3925+
3926+
// These test that setbyte is not modifying a shared value.
3927+
// Since neither bytec nor dup copies, the first test is
3928+
// insufficient, the setbyte changes the original constant (if
3929+
// it fails to copy).
39183930
testAccepts(t, `byte "john"; dup; int 2; int 105; setbyte; pop; byte "john"; ==`, 3)
3931+
testAccepts(t, `byte "jo"; byte "hn"; concat; dup; int 2; int 105; setbyte; pop; byte "john"; ==`, 3)
39193932
}
39203933

39213934
func TestSwap(t *testing.T) {

0 commit comments

Comments
 (0)