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

json.readArray() causes panic when reading empty arrays #4402

Closed
2 tasks done
ChiTimesChi opened this issue Feb 20, 2023 · 3 comments · Fixed by #7348
Closed
2 tasks done

json.readArray() causes panic when reading empty arrays #4402

ChiTimesChi opened this issue Feb 20, 2023 · 3 comments · Fixed by #7348
Assignees
Labels
T-bug Type: bug

Comments

@ChiTimesChi
Copy link
Contributor

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (624797e 2023-02-20T00:07:44.723592254Z)

What command(s) is the bug in?

forge script

Operating System

Linux

Describe the bug

Empty arrays in JSON files cause a panic, when a corresponding json.readTypeArray() is called. Attaching a minimal example:

{
  "tokens": ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"],
  "empty": []
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {console, stdJson, Script} from "forge-std/Script.sol";

contract TestScript is Script {
    using stdJson for string;

    function run() external {
        string memory json = vm.readFile("test.json");
        // This succeeds
        address[] memory tokens = json.readAddressArray(".tokens");
        console.log("Tokens Length: %s", tokens.length);
        // Every one of these causes panic
        json.readAddressArray(".empty");
        json.readBoolArray(".empty");
        json.readBytesArray(".empty");
        json.readBytes32Array(".empty");
        json.readStringArray(".empty");
        json.readIntArray(".empty");
        json.readUintArray(".empty");
    }
}
The application panicked (crashed).
Message:  index out of bounds: the len is 0 but the index is 0
Location: evm/src/executor/inspector/cheatcodes/util.rs:133

This is a bug. Consider reporting it at https://github.com/foundry-rs/foundry

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   1: __libc_start_call_main<unknown>
      at ./csu/../sysdeps/nptl/libc_start_call_main.h:58
   2: __libc_start_main_impl<unknown>
      at ./csu/../csu/libc-start.c:392

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Aborted (core dumped)

Also worth noting that my local .env file contains the line COLORBT_SHOW_HIDDEN=1

@ChiTimesChi ChiTimesChi added the T-bug Type: bug label Feb 20, 2023
@gakonst gakonst added this to Foundry Feb 20, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Feb 20, 2023
@mattsse
Copy link
Member

mattsse commented Feb 20, 2023

cc @odyslam

@odyslam
Copy link
Contributor

odyslam commented Feb 20, 2023

@mattsse can you assign pls

@odyslam
Copy link
Contributor

odyslam commented Feb 25, 2023

Will try to tackle this in the week @ChiTimesChi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

4 participants