From c3e8023ad51ca1ab572a2fbaa9469750aaba5d26 Mon Sep 17 00:00:00 2001 From: Mathias Baumann Date: Mon, 21 Oct 2019 15:14:20 +0200 Subject: [PATCH] Fix wrong assert in overflow check --- Changelog.md | 1 + libsolidity/ast/Types.cpp | 2 +- .../syntaxTests/array/length/not_too_large.sol | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/libsolidity/syntaxTests/array/length/not_too_large.sol diff --git a/Changelog.md b/Changelog.md index bcb3966fb..dfef78edb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ Compiler Features: Bugfixes: * Type Checker: Disallow constructor of the same class to be used as modifier + * Code Generator: Fixed a faulty assert that would wrongly trigger for array sizes exceeding unsigned integer diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 25d31a857..d9636e598 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1849,7 +1849,7 @@ u256 ArrayType::memoryDataSize() const solAssert(m_location == DataLocation::Memory, ""); solAssert(!isByteArray(), ""); bigint size = bigint(m_length) * m_baseType->memoryHeadSize(); - solAssert(size <= numeric_limits::max(), "Array size does not fit u256."); + solAssert(size <= numeric_limits::max(), "Array size does not fit u256."); return u256(size); } diff --git a/test/libsolidity/syntaxTests/array/length/not_too_large.sol b/test/libsolidity/syntaxTests/array/length/not_too_large.sol new file mode 100644 index 000000000..897c28582 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/not_too_large.sol @@ -0,0 +1,10 @@ +// Used to cause ICE because of a too strict assert +pragma experimental ABIEncoderV2; +contract C { + struct S { uint a; T[222222222222222222222222222] sub; } + struct T { uint[] x; } + function f() public returns (uint, S memory) { + } +} +// ---- +// Warning: (52-85): Experimental features are turned on. Do not use experimental features on live deployments.