nspcc-dev/neo-go

Item cast to struct does not ensure/convert field type

已關閉

#3,610 建立於 2024年10月11日

 (0 則留言) (0 個反應) (0 位負責人)Go (108 個分叉)auto 404
I4S4U3bugcompilerhelp wanted

倉庫指標

星標
 (132 顆星)
PR 合併指標
 (平均合併 4天 19小時) (30 天內合併 16 個 PR)

描述

Tried to cast item from contract's storage and use it.

Current Behavior

	newNodes := storage.Find(ctx, newNodesPrefix, storage.None)
	for iterator.Next(newNodes) {
		newNode := iterator.Value(newNodes).(struct {
			key []byte
			val []byte
		})

		newNode.key[0] = 1
	}

leads to SETITEM: invalid item type ByteString

newNode.key[:][0] = 1 solves the issue... why?

Expected Behavior

I said (asserted/converted) that it is a []byte, i want to use it as []byte.

Possible Solution

Ensure, cast or throw an exception at .() operator, not when it is tried to be used later.

Steps to Reproduce

Code from Current Behavior.

Context

https://github.com/nspcc-dev/neofs-contract/pull/438#discussion_r1786975526

Regression

Not sure.

Your Environment

github.com/nspcc-dev/neo-go v0.106.3

貢獻者指南