From 19a792c4cdb6b91c056eac033ac3367af6e67755 Mon Sep 17 00:00:00 2001
From: itchyny <itchyny@cybozu.co.jp>
Date: Mon, 13 Apr 2026 08:46:11 +0900
Subject: [PATCH] Fix NUL truncation in the JSON parser

This fixes CVE-2026-33948.

CVE: CVE-2026-33948
Upstream-Status: Backport [https://github.com/jqlang/jq/commit/6374ae0bcdfe33a18eb0ae6db28493b1f34a0a5b]
Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
---
 src/util.c   | 8 +-------
 tests/shtest | 6 ++++++
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/util.c b/src/util.c
index bcb86da..60ec4d5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -309,13 +309,7 @@ static int jq_util_input_read_more(jq_util_input_state *state) {
       if (p != NULL)
         state->current_line++;
 
-      if (p == NULL && state->parser != NULL) {
-        /*
-         * There should be no NULs in JSON texts (but JSON text
-         * sequences are another story).
-         */
-        state->buf_valid_len = strlen(state->buf);
-      } else if (p == NULL && feof(state->current_input)) {
+      if (p == NULL && feof(state->current_input)) {
         size_t i;
 
         /*
diff --git a/tests/shtest b/tests/shtest
index 887a6bb..a046afe 100755
--- a/tests/shtest
+++ b/tests/shtest
@@ -842,4 +842,10 @@ if ! $msys && ! $mingw; then
   fi
 fi
 
+# CVE-2026-33948: No NUL truncation in the JSON parser
+if printf '{}\x00{}' | $JQ >/dev/null 2> /dev/null; then
+  printf 'Error expected but jq exited successfully\n' 1>&2
+  exit 1
+fi
+
 exit 0
