Skip to content

Commit facfde2

Browse files
author
MarcoFalke
committed
test: Fix CLI_MAX_ARG_SIZE issues
1 parent 73220fc commit facfde2

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

test/functional/rpc_misc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def run_test(self):
3030
lambda: node.echo(arg9='trigger_internal_bug'),
3131
)
3232

33+
self.log.info("test max arg size")
34+
ARG_SZ_COMMON = 131071 # Common limit, used previously in the test framework, serves as a regression test
35+
ARG_SZ_LARGE = 8 * 1024 * 1024 # A large size, which should be rare to hit in practice
36+
for arg_sz in [0, 1, 100, ARG_SZ_COMMON, ARG_SZ_LARGE]:
37+
arg_string = 'a' * arg_sz
38+
assert_equal([arg_string, arg_string], node.echo(arg_string, arg_string))
39+
3340
self.log.info("test getmemoryinfo")
3441
memory = node.getmemoryinfo()['locked']
3542
assert_greater_than(memory['used'], 0)

test/functional/test_framework/test_node.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@
4646
# The size of the blocks xor key
4747
# from InitBlocksdirXorKey::xor_key.size()
4848
NUM_XOR_BYTES = 8
49-
CLI_MAX_ARG_SIZE = 131071 # many systems have a 128kb limit per arg (MAX_ARG_STRLEN)
49+
# Many systems have a 128kB limit for a command size. Depending on the
50+
# platform, this limit may be larger or smaller. Moreover, when using the
51+
# 'bitcoin' command, it may internally insert more args, which must be
52+
# accounted for. There is no need to pick the largest possible value here
53+
# anyway and it should be fine to set it to 1kB in tests.
54+
TEST_CLI_MAX_ARG_SIZE = 1024
5055

5156
# The null blocks key (all 0s)
5257
NULL_BLK_XOR_KEY = bytes([0] * NUM_XOR_BYTES)
@@ -928,10 +933,14 @@ def send_cli(self, clicommand=None, *args, **kwargs):
928933
if clicommand is not None:
929934
p_args += [clicommand]
930935
p_args += pos_args + named_args
931-
max_arg_size = max(len(arg) for arg in p_args)
936+
937+
# TEST_CLI_MAX_ARG_SIZE is set low enough that checking the string
938+
# length is enough and encoding to bytes is not needed before
939+
# calculating the sum.
940+
sum_arg_size = sum(len(arg) for arg in p_args)
932941
stdin_data = self.input
933-
if max_arg_size > CLI_MAX_ARG_SIZE:
934-
self.log.debug(f"Cli: Command size {max_arg_size} too large, using stdin")
942+
if sum_arg_size >= TEST_CLI_MAX_ARG_SIZE:
943+
self.log.debug(f"Cli: Command size {sum_arg_size} too large, using stdin")
935944
rpc_args = "\n".join([arg for arg in p_args[base_arg_pos:]])
936945
if stdin_data is not None:
937946
stdin_data += "\n" + rpc_args

0 commit comments

Comments
 (0)