From b2d07b1858a583449020a0424b1d3ece12ea88aa Mon Sep 17 00:00:00 2001 From: Nicolas BACQUEY Date: Tue, 26 Jul 2022 11:07:38 +0200 Subject: [PATCH] Long_tests/qcheck_rpc: prevent stack overflows when parsing schemas When parsing json schemas in `qcheck_rpc.ml` to generate random RPC inputs, we had two references that were ultimately circular: "tree_encoding" and "inode_tree". Parsing those references would cause stack overflows in `parse_input` and crash the test suite. This commit adds two special cases to `parse_input`, similar to those which are already there for references to "bignum" and "micheline.alpha.michelson_v1.expression". However, note that the two new generators are trivial: they always produce a `Null` json value. Those generators will need to be correctly implmented in a future commit. --- tezt/long_tests/qcheck_rpc.ml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tezt/long_tests/qcheck_rpc.ml b/tezt/long_tests/qcheck_rpc.ml index 8978732b3382..66e3b97a2842 100644 --- a/tezt/long_tests/qcheck_rpc.ml +++ b/tezt/long_tests/qcheck_rpc.ml @@ -91,6 +91,8 @@ type rpc_input = | Object : property list -> rpc_input | One_of : rpc_input list -> rpc_input | Mich_exp : rpc_input + | Tree_encoding : rpc_input + | Inode_tree : rpc_input (* A JSON object field *) and property = {name : string; required : bool; payload : rpc_input} @@ -175,9 +177,11 @@ module RPC_Index = struct let rec parse_input env schema : (rpc_input, string) result = let open Schema in match schema with - (* These first two references are circular. *) + (* These first four references are circular. *) | Ref "bignum" -> Ok Z | Ref "micheline.alpha.michelson_v1.expression" -> Ok Mich_exp + | Ref "tree_encoding" -> Ok Tree_encoding + | Ref "inode_tree" -> Ok Inode_tree | Ref str -> parse_input env @@ String_map.find str env | Other {kind = Boolean; _} -> Ok Boolean | Other {kind = Integer {minimum; maximum; enum = None}; _} -> @@ -365,6 +369,15 @@ module Gen = struct in micheline_node_gen >|= Data_encoding.Json.construct node_encoding + (* TODO: Those trivial implementations are here to prevent the parsing + of "tree_encoding" and "inode_tree" references from generating stack + overflows (these references are circular) and crashing tests. + We ought to make proper implementations if we want the tests + to be significant. *) + let tree_encoding_gen = QCheck2.Gen.return `Null + + let inode_tree_gen = QCheck2.Gen.return `Null + (* Random path generation *) (* ---------------------- *) @@ -422,6 +435,8 @@ module Gen = struct |> QCheck2.Gen.flatten_l |> QCheck2.Gen.map (fun inputs -> `O (List.combine names inputs)) | Mich_exp -> micheline_exp_gen + | Tree_encoding -> tree_encoding_gen + | Inode_tree -> inode_tree_gen let input_gen opt_rpc_input : Ezjsonm.value option t = Option.map known_input_gen opt_rpc_input |> QCheck2.Gen.flatten_opt -- GitLab