Commit Graph
382 Commits
Author SHA1 Message Date
itchyny 601a37f452 Refactor tm2jv to handle fractional seconds removing duplicated code (#3489) 2026-03-01 06:18:14 +09:00
itchyny 22361cfb87 Improve error message truncation with closing delimiters (#3478)
Truncated strings now show closing delimiters: `..."` for strings,
`...]` for arrays, and `...}` for objects, making error messages
clearer.
2026-02-25 08:14:23 +09:00
Ze Sheng a2741ee0a8 Limit number of function parameters and definitions to prevent SEGV (#3460) 2026-02-25 07:49:40 +09:00
bigmoonbit 0eb3da11ed chore: fix typo in tests/jq.test (#3441)
fix typo in  tests/jq.test

Signed-off-by: bigmoonbit <bigmoonbit@outlook.com>
2025-11-27 10:44:45 +01:00
itchyny 5529788292 Fix slurping raw input not to corrupt multi-byte characters (fix #3389) (#3421) 2025-10-31 15:16:29 +09:00
Ish Nagy b29504b4e1 Increase the maximum printing depth from 256 to 10000 (fixes #3413) (#3414) 2025-10-14 14:12:57 +09:00
Sudhakar Verma 589a6947fa jq_fuzz_execute: limit oniguruma depth to 1024 (#3377)
Fixes #3375 - I'll also fix the oss-fuzz build for this in a PR

Signed-off-by: Sudhakar Verma <sudhakar.verma@canonical.com>
2025-10-05 12:50:42 +09:00
A4-Tacks 169457328d Fix rtrimstr("") always output "" (#3415)
Example
---
**Before this fix**:

```sh
$ jq -n '"foo"|rtrimstr("")'
""
```

**After this fix**:

```sh
$ jq -n '"foo"|rtrimstr("")'
"foo"
```
2025-09-29 17:15:43 +02:00
itchyny c8017bf079 Fix localization test for time formatting functions (fix #3368) (#3409) 2025-09-15 07:48:02 +09:00
Alyssa Ross 3c5ceac8e7 jq.test: drop non-portable %F test (#3365)
%F is a non-portable GNU extension, not supported by all strptime
implementations (for example musl's).
2025-07-05 01:25:28 +09:00
Mattias Wadman 499c91bca9 Fixes CVE-2025-49014 which was introduced in 1.8.0 2025-06-19 00:11:01 +02:00
itchyny edbc1da809 Revert "fix: reduce/foreach state variable should not be reset each iteration" (#3349)
This reverts 96e8d893c1. The change
introduced a serious performance regression as reported in #3345.
2025-06-17 15:29:46 +09:00
itchyny a587ddc5a3 Fix syntax error assertion failure (fix #3348) (#3350) 2025-06-17 15:25:46 +09:00
itchyny 7cc202aa6e Fix portability of strptime especially for Windows (#3342) 2025-06-14 08:00:55 +09:00
itchyny d3cf5caf72 Add more test cases for JQ_COLORS support (ref #3288) 2025-05-31 16:29:02 +09:00
SArpnt aa977aa716 Dynamically allocate JQ_COLORS escapes for truecolor support (#3282) 2025-05-31 15:49:17 +09:00
itchyny c6e041699d Fix heap buffer overflow when formatting an empty string
The `jv_string_empty` did not properly null-terminate the string data,
which could lead to a heap buffer overflow. The test case of
GHSA-p7rr-28xf-3m5w (`0[""*0]`) was fixed by the commit dc849e9bb7,
but another case (`0[[]|implode]`) was still vulnerable. This commit
ensures string data is properly null-terminated, and fixes CVE-2025-48060.
2025-05-31 11:46:40 +09:00
Thalia Archibald 9ac6ddae22 Fix whitespace in number parsing (#3195)
* Handle input errors for --indent

Handle malformed and overflowing arguments. Also, forbid leading and
trailing spaces to match the behavior of tonumber from commit ce0e788
(improve tonumber/0 performance by parsing input as number literal,
2024-03-02).

* Do not skip leading whitespace in jvp_strtod

`jvp_strtod` skips leading whitespace, but its decnum counterpart
`decNumberFromString` (called within `jv_number_with_literal`) does not.
Those two are called interchangeably, so it leads to inconsistent
behavior depending on whether the decnum feature is enabled.
Additionally, `classify`, used in the token scanner, only considers
[ \t\n\r] to be whitespace, but `jvp_strtod` consumes the larger set
[ \t\n\v\f\r], so those extra characters are considered literals.

Changing this deviates from the behavior of `strdod` from <stdlib.h> and
is technically a breaking API change, since it is a public symbol.
2025-05-29 04:11:00 +09:00
itchyny aaace5432a Fix parser to allow binary operators for binding syntax (#3326)
Previously, the precedence of `as` binding was higher than the binary
operators. This results in unexpected behaviors, `1 + 2 as $x | -$x`
was `-1` instead of `-3`. The commit 92daac90f6 (PR #3053) changed
the behavior to emit syntax error on this case. Now, this commit allows
binary operators with `as` binding. This fixes #2446, and fixes #3284.
2025-05-23 21:25:30 +09:00
itchyny 4e3088f188 Fix behavior of --slurp --stream when input has no trailing newline character (#3279)
This commit fixes a strange behavior of the combination of `--slurp` and
`--stream` flags when the input has no trailing newline character.
2025-05-22 08:04:05 +09:00
Gabriel Marin 7d8c096e48 Add trimstr/1 function (#3319) 2025-05-21 18:46:04 +09:00
itchyny de21386681 Fix signed integer overflow in jvp_array_write and jvp_object_rehash
This commit fixes signed integer overflow and SEGV issues on growing
arrays and objects. The size of arrays and objects is now limited to
`536870912` (`0x20000000`). This fixes CVE-2024-23337 and fixes #3262.
2025-05-21 07:48:23 +09:00
itchyny b733dfaee7 Improve error messages to show problematic position in the filter (#3292)
This commit improves the parser and compiler error messages, making
it more easier to understand where in the filter the problem is.
Like modern compilers, jq will show the line in the filter where the
error occurred, will display squiggly line under the invalid token.
2025-05-18 16:36:32 +09:00
Brahm Lower c350566001 Adds "toboolean" builtin function for converting strings to booleans (#2098) 2025-05-18 16:31:10 +09:00
itchyny 92daac90f6 Fix unary operator precedence, allow some expressions as object values (#3053)
This commit improves the parser to fix some unintuitive results of the unary
operator `-` (e.g. `[-1 as $x | 1,$x]` is now `[1,-1]`, previously `[-1,-1]`).
Also, this commit now allows to use binary operator expressions, `reduce`,
`foreach`, `if`, and `try` expressions for object values.
2025-05-18 16:13:55 +09:00
itchyny b088e83a82 Refactor splits/2 using foreach syntax (remove private filter _nwise) (#3260)
This commit refactors `splits/2` implementation using `foreach` syntax
and reduces intermediate arrays. This refactoring removes an unnecessary
private (and undocumented) filter `_nwise` and closes #3148.
2025-05-18 08:27:44 +09:00
Steven Ihde 77d23e9a5f Test daylight time for strflocaltime (#3323)
This test case covers the behavior described in issue #1912, fixed by #3203.
2025-05-15 07:16:25 +09:00
Thomas Sibley 931a362f8b docs: Use a better input example in the streaming section (#3322)
The introduction says all the usage examples (e.g. of truncate_stream,
etc) in the section use [0,[1]] as input, but they actually use [1,[2]].
["a",["b"]] seems better than [1,[2]] as the string values won't be
confusable with the indexes in <path>.
2025-05-14 20:46:31 +09:00
liviubobocu 4b84a6e2f6 Include column number in parser and compiler error messages (#3257)
Resolves #1027, resolves #2334, and resolves #3256.
2025-03-10 22:17:49 +09:00
itchyny 94fd973ebb Fix calloc error on @base64d format (ref #3280) (#3286)
This commit fixes a regression of a8ce2ff, e.g. `"=" | @base64d`.
2025-03-06 04:30:46 +09:00
Nicole Wren c70ae1ada4 fix: foreach should not break init backtracking with DUPN (#3266)
Simplifies the compilation of `foreach` to avoid the problem in #3227 by
removing unnecessary `FORK ... BACKTRACK`.

Does not address `reduce`, which is less trivial.
2025-03-05 22:01:48 +09:00
SArpnt 9d6efec198 fix: unset environment variables before shtests (#3283)
Tests no longer fail if `JQ_COLORS` and `NO_COLOR` are already set.
2025-03-05 07:59:46 +09:00
itchyny a09a4dfd55 Reject NaN with payload while parsing JSON
This commit drops support for parsing NaN with payload in JSON like
`NaN123` and fixes CVE-2024-53427. Other JSON extensions like `NaN` and
`Infinity` are still supported. Fixes #3023, fixes #3196, fixes #3246.
2025-03-05 07:43:54 +09:00
itchyny a8ce2ff09a Avoid zero-length calloc (#3280)
Using `calloc` function with a count of zero elements is implementation
defined and it may cause allocation errors on some platforms (ref #3277).
This commit fixes `jv_mem_calloc` callers to avoid undefined behavior.
2025-03-04 22:33:51 +09:00
itchyny dc849e9bb7 Improve performance of repeating strings (#3272)
This commit improves the performance of repeating strings, by copying
the result string instead of the string being repeated. Also it adds
an error message when the result string is too long.
2025-03-04 22:13:55 +09:00
itchyny 5df471fa5b Disable Valgrind by default during testing (#3269)
Previously, the configure script automatically enables Valgrind during
testing when the valgrind command is found. However, running tests with
Valgrind is quite slow, so it is better to disable it by default, and
to enable it only when the user specifies the `--enable-valgrind` flag.
2025-03-04 22:12:25 +09:00
itchyny c4e1fb08fb Support CRLF line breaks in filters (#3274) 2025-03-04 22:11:40 +09:00
itchyny b7a1201b72 Preserve numerical precision on length/0 (#3275) 2025-03-04 22:09:33 +09:00
itchyny 17be97a8ad Define _BSD_SOURCE in builtin.c for OpenBSD support (#3278)
On OpenBSD, some prototypes are hidden behind `_BSD_SOURCE`.
Defining this variable fixes #3252, and also fixes #3276.
This can be seen as a regression of #2631.
2025-03-04 21:39:52 +09:00
Marcin Serwin f3d4c1165d fix: copy the string returned by getenv (#3264) 2025-02-18 07:54:13 +09:00
itchyny 70e72abea3 Fix compiler warning type-limits in found_string (ref #2911) (#3263)
Whether `char` has a sign is implementation dependent, and `c >= 0` may
result in a compiler warning. We can use bitwise operator to check
whether the character is a control character, regardless of the sign.
2025-02-18 07:52:58 +09:00
Marcin Serwin 6d8e9f98ae fix: populate timezone data when formatting time (#3203)
The `jv2tm` function was zeroing fields of `struct tm` that were not
specified by the standard. However, depending on the libc this produced
incorrect timezone data when used together with formatting functions.
This change tries to fill the timezone data using either `mktime`,
`timegm`, or manually.

Apple's Libc implementation contains a bug which causes it to ignore
the offset data present in the `struct tm` in favor of the older heuristic
needed by legacy standards. This workaround temporarily sets the global
timezone so it gets picked up during formatting.
2025-02-17 21:41:01 +09:00
itchyny 64bd8ba374 fix: jv_dump_string_trunc should not break unicode characters (#3249) 2025-02-16 21:40:18 +09:00
itchyny 6ce3bdf382 fix: preserve numerical precision on unary negation (#3242) 2025-02-06 07:50:21 +09:00
Mattias Wadman 2755664a8e Non-matched optional capture group should be null and offset -1 (#3238)
Fixes #3093
2025-02-04 19:18:58 +01:00
d0adcbfebb Fix --indent 0 implicitly enabling compact-output (#3232)
Now it will retain pretty-printing, just remove any indentation.

Co-authored-by: Andrew Marshall <andrew@johnandrewmarshall.com>
Co-authored-by: Gabriel Marin <marin.gabriel@protonmail.com>
2025-02-01 15:09:30 +09:00
itchyny ce54621904 docs: mention the behavior of scan using regex with capturing groups (#3240) 2025-01-28 11:41:17 +09:00
Han Jiang da28628edd Fix redundant subexpression in Generators and iterators example in doc (#3239) 2025-01-27 19:45:27 +09:00
itchyny 31dac287cc tests: quote .[] in shtest which can break syntax highlight (#3235) 2025-01-26 08:08:31 +09:00
Eloy Coto 562ffec869 refactor: move bsearch function to C-code (#2945)
This commit fixes issue #527 and move the bsearch function to a native
C-code. This change improves the performance of this function.
2025-01-25 22:09:43 +09:00