# Solidity Empty Byte Array Copy Bug

By [高可用匿名性学习笔记](https://paragraph.com/@0x4ca146039c567a8cbfde83c23a515b587d9be469) · 2022-10-24

---

2020年10月4日, [John Toman](https://www.johnadtoman.com) 发现该漏洞。

影响范围 version < 0.7.4, 中危。

### 漏洞简述

依次执行以下三个操作将造成，`bytes`、`string`被非零值初始化。

*   从 `memory`/`calldata` copy 空的`bytes`/`string` 到 `storage` 中
    
*   对该storage中的 `bytes`/`string` 做 `.push()` 操作，使length增长。
    
*   在向新空间写入前，直接读取
    

举例如下:

    contract C {
        bytes data;
        function f() public returns (bytes memory) {
            uint[2] memory x;
            x[0] = type(uint).max; // 先在memory中存点别的东西
            bytes memory t;
            data = t;
            data.push();
            return data; // 这里会越界读到 x 的值，返回值会是 0xff 而非 0x00
        }
    }

---

*Originally published on [高可用匿名性学习笔记](https://paragraph.com/@0x4ca146039c567a8cbfde83c23a515b587d9be469/solidity-empty-byte-array-copy-bug)*
