# Copying malicious calldata to memory in Assembly

**URL:** <https://forum.openzeppelin.com/t/copying-malicious-calldata-to-memory-in-assembly/3314>\
**Category:** SDK\
**Created:** [July 13, 2020, 11:48pm UTC](https://forum.openzeppelin.com/t/copying-malicious-calldata-to-memory-in-assembly/3314 "2020-07-13T23:48:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![junderw](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/junderw/32/2701_2.png) [@junderw](https://forum.openzeppelin.com/u/junderw)\
**Post date:** [July 13, 2020, 11:48pm UTC](https://forum.openzeppelin.com/t/copying-malicious-calldata-to-memory-in-assembly/3314/1 "2020-07-13T23:48:27Z")

</div>

I am looking at the assembly in Proxy.sol (reference below)

> <https://github.com/OpenZeppelin/openzeppelin-sdk/blob/3e2860ef7d5ea2d0397e0c5d25ed1d215d1e79f2/packages/lib/contracts/upgradeability/Proxy.sol#L31-L48>

Question: What if someone calls the Proxy with some malformed / extremely large piece of data, won’t calldatacopy have free reign over the entire memory? Overwriting free memory pointer at 0x40 etc.? Also, can the same be said for returndatacopy? I know returndata will be from our implementation logic, so it shouldn’t be malformed.

I’m sure there’s some simple answer, ie. “memory is independent for each subsequent call, so as long as we don’t return to non-assembly in this contract’s call frame, memory doesn’t matter since nothing will access it in any meaningful way.”

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [July 14, 2020, 1:22am UTC](https://forum.openzeppelin.com/t/copying-malicious-calldata-to-memory-in-assembly/3314/2 "2020-07-14T01:22:51Z")

</div>

Hi @junderw,

Welcome to the community 👋

I don’t know the answer unfortunately, I tried looking through the Solidity documentation on assembly/Yul but didn’t find the simple answer. I will see what I can find out or hopefully someone from the community can provide the answer.

---

<div class="post-metadata">

**Author:** ![junderw](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/junderw/32/2701_2.png) [@junderw](https://forum.openzeppelin.com/u/junderw)\
**Post date:** [July 14, 2020, 12:58pm UTC](https://forum.openzeppelin.com/t/copying-malicious-calldata-to-memory-in-assembly/3314/3 "2020-07-14T12:58:29Z")

</div>

From gitter

> Marius van der Wijden @MariusVanDerWijden 21:53  
> Afaik we create a new stack for every call into another contract, see

> <https://github.com/ethereum/go-ethereum/blob/5b081ab214d8d6373cbfdd9464f2503934b9bb68/core/vm/interpreter.go#L166>

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [July 14, 2020, 2:18pm UTC](https://forum.openzeppelin.com/t/copying-malicious-calldata-to-memory-in-assembly/3314/4 "2020-07-14T14:18:11Z")

</div>

> [@junderw](#):
>
> memory is independent for each subsequent call, so as long as we don’t return to non-assembly in this contract’s call frame, memory doesn’t matter since nothing will access it in any meaningful way

Exactly! 🙂
