mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-15 16:38:23 +01:00
test: Fix CLI_MAX_ARG_SIZE issues
Github-Pull: #33243
Rebased-From: facfde2cdc
This commit is contained in:
@@ -30,6 +30,13 @@ class RpcMiscTest(BitcoinTestFramework):
|
|||||||
lambda: node.echo(arg9='trigger_internal_bug'),
|
lambda: node.echo(arg9='trigger_internal_bug'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.log.info("test max arg size")
|
||||||
|
ARG_SZ_COMMON = 131071 # Common limit, used previously in the test framework, serves as a regression test
|
||||||
|
ARG_SZ_LARGE = 8 * 1024 * 1024 # A large size, which should be rare to hit in practice
|
||||||
|
for arg_sz in [0, 1, 100, ARG_SZ_COMMON, ARG_SZ_LARGE]:
|
||||||
|
arg_string = 'a' * arg_sz
|
||||||
|
assert_equal([arg_string, arg_string], node.echo(arg_string, arg_string))
|
||||||
|
|
||||||
self.log.info("test getmemoryinfo")
|
self.log.info("test getmemoryinfo")
|
||||||
memory = node.getmemoryinfo()['locked']
|
memory = node.getmemoryinfo()['locked']
|
||||||
assert_greater_than(memory['used'], 0)
|
assert_greater_than(memory['used'], 0)
|
||||||
|
|||||||
@@ -48,7 +48,12 @@ BITCOIND_PROC_WAIT_TIMEOUT = 60
|
|||||||
# The size of the blocks xor key
|
# The size of the blocks xor key
|
||||||
# from InitBlocksdirXorKey::xor_key.size()
|
# from InitBlocksdirXorKey::xor_key.size()
|
||||||
NUM_XOR_BYTES = 8
|
NUM_XOR_BYTES = 8
|
||||||
CLI_MAX_ARG_SIZE = 131071 # many systems have a 128kb limit per arg (MAX_ARG_STRLEN)
|
# Many systems have a 128kB limit for a command size. Depending on the
|
||||||
|
# platform, this limit may be larger or smaller. Moreover, when using the
|
||||||
|
# 'bitcoin' command, it may internally insert more args, which must be
|
||||||
|
# accounted for. There is no need to pick the largest possible value here
|
||||||
|
# anyway and it should be fine to set it to 1kB in tests.
|
||||||
|
TEST_CLI_MAX_ARG_SIZE = 1024
|
||||||
|
|
||||||
# The null blocks key (all 0s)
|
# The null blocks key (all 0s)
|
||||||
NULL_BLK_XOR_KEY = bytes([0] * NUM_XOR_BYTES)
|
NULL_BLK_XOR_KEY = bytes([0] * NUM_XOR_BYTES)
|
||||||
@@ -951,10 +956,14 @@ class TestNodeCLI():
|
|||||||
if clicommand is not None:
|
if clicommand is not None:
|
||||||
p_args += [clicommand]
|
p_args += [clicommand]
|
||||||
p_args += pos_args + named_args
|
p_args += pos_args + named_args
|
||||||
max_arg_size = max(len(arg) for arg in p_args)
|
|
||||||
|
# TEST_CLI_MAX_ARG_SIZE is set low enough that checking the string
|
||||||
|
# length is enough and encoding to bytes is not needed before
|
||||||
|
# calculating the sum.
|
||||||
|
sum_arg_size = sum(len(arg) for arg in p_args)
|
||||||
stdin_data = self.input
|
stdin_data = self.input
|
||||||
if max_arg_size > CLI_MAX_ARG_SIZE:
|
if sum_arg_size >= TEST_CLI_MAX_ARG_SIZE:
|
||||||
self.log.debug(f"Cli: Command size {max_arg_size} too large, using stdin")
|
self.log.debug(f"Cli: Command size {sum_arg_size} too large, using stdin")
|
||||||
rpc_args = "\n".join([arg for arg in p_args[base_arg_pos:]])
|
rpc_args = "\n".join([arg for arg in p_args[base_arg_pos:]])
|
||||||
if stdin_data is not None:
|
if stdin_data is not None:
|
||||||
stdin_data += "\n" + rpc_args
|
stdin_data += "\n" + rpc_args
|
||||||
|
|||||||
Reference in New Issue
Block a user