Skip to content

Fix panic on negative slice indices that underflow after adjustment - #2646

Merged
mikefarah merged 1 commit into
mikefarah:masterfrom
jandubois:fix-slice-negative-index
Apr 6, 2026
Merged

mikefarah merged 1 commit into
mikefarah:masterfrom
jandubois:fix-slice-negative-index

Conversation

@jandubois

Copy link
Copy Markdown
Contributor

sliceArrayOperator adjusts negative indices by adding Content length, but does not clamp the result. When the absolute value of a negative index exceeds Content length (e.g. .[-99999:3] on a 3-element array), the adjusted index remains negative and causes an out-of-bounds access in the Content slice loop.

Extract the adjust-and-clamp logic into clampSliceIndex and use it for both index positions.

Reproducer (panics before this fix, returns full array after):

echo '[a, b, c]' | yq '.[-99999:3]'

Found by OSS-Fuzz via the lima project's FuzzEvaluateExpression target. https://issues.oss-fuzz.com/issues/438776028

sliceArrayOperator adjusts negative indices by adding Content length,
but does not clamp the result. When the absolute value of a negative
index exceeds Content length (e.g. .[-99999:3] on a 3-element array),
the adjusted index remains negative and causes an out-of-bounds access
in the Content slice loop.

Extract the adjust-and-clamp logic into clampSliceIndex and use it for
both index positions.

Reproducer (panics before this fix, returns full array after):

    echo '[a, b, c]' | yq '.[-99999:3]'

Found by OSS-Fuzz via the lima project's FuzzEvaluateExpression target.
https://issues.oss-fuzz.com/issues/438776028

Signed-off-by: Jan Dubois <jan@jandubois.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mikefarah

Copy link
Copy Markdown
Owner

Love your work @jandubois

@mikefarah
mikefarah merged commit 80139ae into mikefarah:master Apr 6, 2026
3 checks passed
@jandubois
jandubois deleted the fix-slice-negative-index branch April 6, 2026 17:00
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request May 7, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [mikefarah/yq](https://github.com/mikefarah/yq) | minor | `v4.52.5` → `v4.53.2` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>mikefarah/yq (mikefarah/yq)</summary>

### [`v4.53.2`](https://github.com/mikefarah/yq/releases/tag/v4.53.2)

[Compare Source](mikefarah/yq@v4.52.5...v4.53.2)

- Releases and tags now signed and immutable!
- Add system(command; args) operator (disabled by default) ([#&#8203;2640](mikefarah/yq#2640))
- TOML encoder: prefer readable table sections over inline tables ([#&#8203;2649](mikefarah/yq#2649))
- Fix TOML encoder to quote keys containing special characters ([#&#8203;2648](mikefarah/yq#2648))
- Add string slicing support ([#&#8203;2639](mikefarah/yq#2639))
- Fix findInArray misuse on MappingNodes in equality and contains ([#&#8203;2645](mikefarah/yq#2645)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Fix panic on negative slice indices that underflow after adjustment ([#&#8203;2646](mikefarah/yq#2646)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Fix stack overflow from circular alias in traverse ([#&#8203;2647](mikefarah/yq#2647)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Fix panic and OOM in repeatString for large repeat counts ([#&#8203;2644](mikefarah/yq#2644)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Bumped dependencies

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMjcuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEyNy4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6bWlub3IiXX0=-->
eleboucher pushed a commit to eleboucher/runner that referenced this pull request May 28, 2026
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [forgejo-runner-service-yq](https://github.com/mikefarah/yq) | minor | `v4.52.4` → `v4.53.2` |

---

### Release Notes

<details>
<summary>mikefarah/yq (forgejo-runner-service-yq)</summary>

### [`v4.53.2`](https://github.com/mikefarah/yq/releases/tag/v4.53.2)

[Compare Source](mikefarah/yq@v4.52.5...v4.53.2)

- Releases and tags now signed and immutable!
- Add system(command; args) operator (disabled by default) ([#&#8203;2640](mikefarah/yq#2640))
- TOML encoder: prefer readable table sections over inline tables ([#&#8203;2649](mikefarah/yq#2649))
- Fix TOML encoder to quote keys containing special characters ([#&#8203;2648](mikefarah/yq#2648))
- Add string slicing support ([#&#8203;2639](mikefarah/yq#2639))
- Fix findInArray misuse on MappingNodes in equality and contains ([#&#8203;2645](mikefarah/yq#2645)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Fix panic on negative slice indices that underflow after adjustment ([#&#8203;2646](mikefarah/yq#2646)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Fix stack overflow from circular alias in traverse ([#&#8203;2647](mikefarah/yq#2647)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Fix panic and OOM in repeatString for large repeat counts ([#&#8203;2644](mikefarah/yq#2644)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Bumped dependencies

### [`v4.52.5`](https://github.com/mikefarah/yq/releases/tag/v4.52.5)

[Compare Source](mikefarah/yq@v4.52.4...v4.52.5)

- Fix: reset TOML decoder state between files ([#&#8203;2634](mikefarah/yq#2634)) thanks [@&#8203;terminalchai](https://github.com/terminalchai)
  - Fix: preserve original filename when using --front-matter ([#&#8203;2613](mikefarah/yq#2613)) thanks [@&#8203;cobyfrombrooklyn-bot](https://github.com/cobyfrombrooklyn-bot)
  - Fix typo in filename ([#&#8203;2611](mikefarah/yq#2611)) thanks [@&#8203;alexandear](https://github.com/alexandear)
  - Bumped dependencies

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - Between 12:00 AM and 03:59 AM (`* 0-3 * * *`)
- Automerge
  - Between 12:00 AM and 03:59 AM (`* 0-3 * * *`)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xOTUuMSIsInVwZGF0ZWRJblZlciI6IjQzLjE5NS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJLaW5kL0RlcGVuZGVuY3lVcGRhdGUiLCJydW4tZW5kLXRvLWVuZC10ZXN0cyJdfQ==-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1536
hbjydev pushed a commit to hbjydev/phoebe that referenced this pull request Aug 27, 2026
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [yq](https://github.com/mikefarah/yq) | minor | `4.52.4` → `4.53.6` |

---

> ⚠️ **Warning**
>
> Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/141) for more information.

---

### Release Notes

<details>
<summary>mikefarah/yq (yq)</summary>

### [`v4.53.6`](https://github.com/mikefarah/yq/releases/tag/v4.53.6)

[Compare Source](mikefarah/yq@v4.53.4...v4.53.6)

- Fixing release build issue
  - Fixed line wrapping bug ([#&#8203;2824](mikefarah/yq#2824), [#&#8203;2823](mikefarah/yq#2823)) Thanks [@&#8203;mxey](https://github.com/mxey)
  - Bumped dependencies

### [`v4.53.4`](https://github.com/mikefarah/yq/releases/tag/v4.53.4)

[Compare Source](mikefarah/yq@v4.53.3...v4.53.4)

- Close input files after processing each one ([#&#8203;2796](mikefarah/yq#2796)) ([#&#8203;2808](mikefarah/yq#2808)) Thanks [@&#8203;MsfPablo](https://github.com/MsfPablo)
- Fixed non string HCL string keys ([#&#8203;2795](mikefarah/yq#2795))
- Fixed heap allocation bug ([#&#8203;2809](mikefarah/yq#2809)) Thanks [@&#8203;MsfPablo](https://github.com/MsfPablo)
- Fix deleting commented empty list YAML output ([#&#8203;2765](mikefarah/yq#2765)) Thanks [@&#8203;dpersek](https://github.com/dpersek)
- Fix (has) return false for negative array indices ([#&#8203;2769](mikefarah/yq#2769)) Thanks [@&#8203;maximilize](https://github.com/maximilize)
- Fix (sort): avoid int64 overflow comparing large integers ([#&#8203;2771](mikefarah/yq#2771)) Thanks [@&#8203;maximilize](https://github.com/maximilize)
- Fix: preserve correct parent references in explode merge anchor reconstruction ([#&#8203;2730](mikefarah/yq#2730)) Thanks [@&#8203;vomba](https://github.com/vomba)
- Improve Guard ExpressionParser initialization with sync.Once ([#&#8203;2789](mikefarah/yq#2789)) Thanks [@&#8203;arcaven](https://github.com/arcaven)
- Fix: reject negative indent instead of panicking ([#&#8203;2746](mikefarah/yq#2746)) Thanks [@&#8203;StressTestor](https://github.com/StressTestor)
- Fix: parse signed hex and octal integers ([#&#8203;2749](mikefarah/yq#2749)) Thanks [@&#8203;StressTestor](https://github.com/StressTestor)
- Fix: skip UTF-8 BOM when processing front matter ([#&#8203;2751](mikefarah/yq#2751)) Thanks [@&#8203;StressTestor](https://github.com/StressTestor)
- Fix !!merge tag regression for yq  ([#&#8203;2705](mikefarah/yq#2705)) Thanks [@&#8203;W-Floyd](https://github.com/W-Floyd)
- Default to yaml when a file's extension is not a recognised format ([#&#8203;2785](mikefarah/yq#2785)) Thanks [@&#8203;devthedevil](https://github.com/devthedevil)
- Bumped dependencies

### [`v4.53.3`](https://github.com/mikefarah/yq/releases/tag/v4.53.3)

[Compare Source](mikefarah/yq@v4.53.2...v4.53.3)

- Add `--ini-preserve-quotes` flag for INI round-trip quote preservation ([#&#8203;2728](mikefarah/yq#2728)) Thanks [@&#8203;toller892](https://github.com/toller892)!
- Fix: reset INI decoder state on init ([#&#8203;2719](mikefarah/yq#2719)) Thanks [@&#8203;xieby1](https://github.com/xieby1)!
- Fix: decode properties array bracket paths ([#&#8203;2693](mikefarah/yq#2693)) Thanks [@&#8203;cyphercodes](https://github.com/cyphercodes)!
- Fix: preserve floats with trailing zero when encoding YAML to JSON ([#&#8203;2701](mikefarah/yq#2701)) Thanks [@&#8203;ChrisJr404](https://github.com/ChrisJr404)!
- Fix: JSON to TOML root scope and null handling ([#&#8203;2689](mikefarah/yq#2689)) Thanks [@&#8203;LovesAsuna](https://github.com/LovesAsuna)!
- Fix: reset TOML decoder finished flag on Init for multi-doc evaluation ([#&#8203;2704](mikefarah/yq#2704)) Thanks [@&#8203;terminalchai](https://github.com/terminalchai)!
- Fix: reset TOML decoder between files when evaluating all at once ([#&#8203;2685](mikefarah/yq#2685)) Thanks [@&#8203;terminalchai](https://github.com/terminalchai)!
- Fix: preserve TOML inline table array scope ([#&#8203;2694](mikefarah/yq#2694)) Thanks [@&#8203;cyphercodes](https://github.com/cyphercodes)!
- Fix: preserve empty TOML arrays in tables ([#&#8203;2686](mikefarah/yq#2686)) Thanks [@&#8203;cyphercodes](https://github.com/cyphercodes)!
- Fix: TOML encoder uses inline tables for YAML FlowStyle mappings ([#&#8203;2687](mikefarah/yq#2687))
- Fix nested inline YAML merge explode ([#&#8203;2699](mikefarah/yq#2699)) Thanks [@&#8203;cyphercodes](https://github.com/cyphercodes)!
- Fix repeatString overflow test on 32-bit platforms ([#&#8203;2680](mikefarah/yq#2680)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Bumped dependencies

### [`v4.53.2`](https://github.com/mikefarah/yq/releases/tag/v4.53.2)

[Compare Source](mikefarah/yq@v4.52.5...v4.53.2)

- Releases and tags now signed and immutable!
- Add system(command; args) operator (disabled by default) ([#&#8203;2640](mikefarah/yq#2640))
- TOML encoder: prefer readable table sections over inline tables ([#&#8203;2649](mikefarah/yq#2649))
- Fix TOML encoder to quote keys containing special characters ([#&#8203;2648](mikefarah/yq#2648))
- Add string slicing support ([#&#8203;2639](mikefarah/yq#2639))
- Fix findInArray misuse on MappingNodes in equality and contains ([#&#8203;2645](mikefarah/yq#2645)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Fix panic on negative slice indices that underflow after adjustment ([#&#8203;2646](mikefarah/yq#2646)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Fix stack overflow from circular alias in traverse ([#&#8203;2647](mikefarah/yq#2647)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Fix panic and OOM in repeatString for large repeat counts ([#&#8203;2644](mikefarah/yq#2644)) Thanks [@&#8203;jandubois](https://github.com/jandubois)!
- Bumped dependencies

### [`v4.52.5`](https://github.com/mikefarah/yq/releases/tag/v4.52.5)

[Compare Source](mikefarah/yq@v4.52.4...v4.52.5)

- Fix: reset TOML decoder state between files ([#&#8203;2634](mikefarah/yq#2634)) thanks [@&#8203;terminalchai](https://github.com/terminalchai)
  - Fix: preserve original filename when using --front-matter ([#&#8203;2613](mikefarah/yq#2613)) thanks [@&#8203;cobyfrombrooklyn-bot](https://github.com/cobyfrombrooklyn-bot)
  - Fix typo in filename ([#&#8203;2611](mikefarah/yq#2611)) thanks [@&#8203;alexandear](https://github.com/alexandear)
  - Bumped dependencies

</details>

---

### Configuration

📅 **Schedule**: (in timezone Europe/London)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNjAuMiIsInVwZGF0ZWRJblZlciI6IjQzLjI2MC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9naXRodWItcmVsZWFzZSIsInR5cGUvbWlub3IiXX0=-->

Reviewed-on: https://forgejo.hayden.moe/hayden/phoebe/pulls/363
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants