]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: json: Increase JSON nesting limit when parsing to 300
authorPeter Krempa <pkrempa@redhat.com>
Thu, 11 Dec 2025 08:39:03 +0000 (09:39 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 5 Jan 2026 14:15:25 +0000 (15:15 +0100)
The default in json-c is 32 which is too low to accomodate the 200
snapshot layers we supported historically in the qemu driver (200 is
picked based on the 256 layer limit in libxml).

The response to 'query-block' is otherwise too low and we fail to start
the VM when there's around 26 images in a backing chain.

'json_tokener_new_ex' is supported since json-c 0.11 and we require at
least 0.14.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virjson.c

index a799707c163fbf36aee6ffd44f69539bfafb025c..454bd657beb69c33947cb17d7473128d1309b1fa 100644 (file)
@@ -1466,7 +1466,15 @@ virJSONValueFromString(const char *jsonstring)
 
     VIR_DEBUG("string=%s", jsonstring);
 
-    tok = json_tokener_new();
+    /* When creating the tokener we need to specify the limit of the nesting
+     * depth of JSON objects. The default in json-c is 32. Since we need to
+     * support at least 200 layers of snapshots (the limit is based on a
+     * conservative take on the 256 layer nesting limit for XML in libxml), for
+     * which we have internal checks, we also need to set the JSON limit to
+     * be able to parse qemu responses for such a deeply nested snapshot list.
+     * '300' is picked a sa conservative buffer on top of the 200 layers plus
+     * some of the extra wrappers that qemu adds*/
+    tok = json_tokener_new_ex(300);
     if (!tok) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("failed to create JSON tokener"));