Skip to content
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

Wrong parsing dynamicBytes and unsafe ABI decoding #801

Open
6od9i opened this issue Mar 15, 2023 · 0 comments · Fixed by #803
Open

Wrong parsing dynamicBytes and unsafe ABI decoding #801

6od9i opened this issue Mar 15, 2023 · 0 comments · Fixed by #803
Labels
bug Something isn't working

Comments

@6od9i
Copy link
Contributor

6od9i commented Mar 15, 2023

What happened?

When parse response with dynamicBytes by method decodeSingleType, from ABIDecoding file, to array of responses set not new Data with bounds [0<..count], but slice for example on screenshot [32<..64]
photo_2023-03-15 10 01 39

And when i try to decode my values from this responses array with slices, ABIDecoder checks only size of data to avoid out of bounds
guard data.count >= pointer + type.memoryUsage else {return (nil, nil)}

and this data has correct size, and this check is succeed, but data is slice with bounds [32<..64], and it is crashed in
let elementItself = data[pointer ..< pointer + type.memoryUsage]
because pointer = 0, and type.memoryUsage = 32

What are the steps to reproduce?

1 request aggregated method for getting balances of some different tokens by methods "balanceOf" and "getEthBalance" , for example for 3 tokens from one wallet in one network with "createReadOperation" from Web3.Contract with aggregate ABI
2 try to decode response with contract's method contract.methods[methodName].decodeReturnData
3 app is crashed

What is the expected behavior?

I expect that work fine and not crashed, i think this fix solved the problem
replace
let elementItself = data[pointer ..< pointer + type.memoryUsage]
to
let elementItself = data[data.indices.startIndex + Int(pointer) ..< data.indices.startIndex + Int(pointer + type.memoryUsage)]

it will more safe, than previous because protect us from any slices of data

What is the error thrown?

EXC_BREAKPOINT (code=1, subcode=0x1aeb9fcb4)

What's the stack trace said?

#2 0x0000000103462ab8 in static ABIDecoder.followTheData(type:data:pointer:) at web3swift/Sources/Web3Core/EthereumABI/ABIDecoding.swift:191

OS version

iOS 16.1.1

Library version

"branch" : "develop",
"revision" : "2357868ce27009c5dec6b7a9f64d0a520e85b9af"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant