Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: index out of range [1] with length 1 #2211

Closed
jandubois opened this issue Dec 3, 2024 · 5 comments
Closed

panic: runtime error: index out of range [1] with length 1 #2211

jandubois opened this issue Dec 3, 2024 · 5 comments
Labels

Comments

@jandubois
Copy link
Contributor

jandubois commented Dec 3, 2024

This bug was detected by oss-fuzz and reported in https://issues.oss-fuzz.com/issues/42537678.

There is a PR with a fix in #2112, but it has been closed because it was missing a test case.

The issue with the test case was that both the data and the command were longish strings of garbage created by the fuzzer. I've been able to manually reduce it to:

$ echo $'!!null\n-' | yq $'.\r'
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
github.com/mikefarah/yq/v4/pkg/yqlib.doTraverseMap(0xc0000435e8, 0x9?, {0x7ff7bdf7024c, 0x1}, {0x0, 0x0, 0x0, 0x0, 0x0}, 0x0)
	github.com/mikefarah/yq/v4/pkg/yqlib/operator_traverse_path.go:269 +0x334
github.com/mikefarah/yq/v4/pkg/yqlib.traverseMap({0xc0002dc270, 0x0, 0x0, {0x0, 0x0}}, 0xc00022a0e0, 0xc00022a380, {0x0, 0x0, 0x0, ...}, ...)
	github.com/mikefarah/yq/v4/pkg/yqlib/operator_traverse_path.go:223 +0xe7

@mikefarah I'm not sure if you want to include fuzzer-generated tests, and where best to put this. You offered in #2112 to add it yourself if you get a repro scenario, so any help would be appreciated.

The fuzzing results were part of a CNCF sponsored audit, and this issue is mentioned in the report at https://github.com/lima-vm/lima/blob/master/docs/reports/Ada-Logics-Lima-fuzzing-audit-2024.pdf on page 35.

Original reproducer
func TestEvaluateExpressionPoc(t *testing.T) {
        expression := string([]byte{46,13,13})
        content := []byte{13, 63, 13, 13, 13, 13, 13, 13, 45, 45, 45, 10,
                13, 52, 13, 13, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
                51, 51, 51, 51, 51, 13, 13, 13, 13, 13, 13, 13, 63, 13, 13, 13,
                13, 13, 13, 45, 45, 45, 64, 13, 122, 45, 46, 45, 10, 13, 13, 13,
                13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 63, 13, 13,
                13, 13, 13, 13, 45, 45, 45, 10, 13, 13, 13, 13, 114, 100, 48,
                13, 13, 13, 13, 63, 13, 13, 13, 13, 13, 13, 45, 45, 45, 10, 13,
                13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 63,
                13, 13, 13, 13, 13, 13, 45, 45, 45, 10, 33, 33, 110, 117, 108,
                108, 13, 13, 13, 13, 13, 35, 45, 51, 10, 51, 45, 45, 10, 13, 13,
                13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 63, 13,
                13, 13, 13, 13, 13, 45, 45, 45, 10, 13, 13, 13, 63, 13, 13, 13,
                13, 13, 13, 45, 45, 45, 13, 13, 45, 45, 45, 64, 13, 122, 45,
                46, 45, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
                13, 13, 13, 63, 13, 13, 13, 13, 13, 13, 45, 45, 45, 10, 13, 13,
                13, 13, 114, 100, 48, 13, 13, 13, 13, 63, 13, 13, 13, 13, 13,
                13, 45, 45, 45, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
                13, 13, 13, 13, 13, 63, 13, 13, 13, 13, 13, 13, 45, 45, 45, 10,
                33, 33, 110, 117, 108, 108, 13, 13, 45}
        _, _ = EvaluateExpression(expression, content)
}
mikefarah added a commit that referenced this issue Dec 7, 2024
@mikefarah
Copy link
Owner

Fixed - not sure about these fuzzer tests, they're quite odd. In this case, it somehow caused the underlying library to create a map that only had a key.

@mikefarah
Copy link
Owner

mikefarah commented Dec 7, 2024

Thanks for investigating though :)

@mikefarah
Copy link
Owner

On looking at the traces for these tests, despite the strange generated inputs I think they are worthwhile fixes 👍🏼

@mikefarah
Copy link
Owner

Fixed in 4.4.6

@jandubois
Copy link
Contributor Author

I think they are worthwhile fixes

Ok, when I have time I'll try to see if there are more yq related reports. The fuzzers keep running on spare Google CPU cycles, trying random input, and occasionally file new bugs, but they won't become public for 3 or 6 months, can't remember how long exactly.

tmeijn pushed a commit to tmeijn/dotfiles that referenced this issue Dec 9, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [mikefarah/yq](https://github.com/mikefarah/yq) | patch | `v4.44.5` -> `v4.44.6` |

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.44.6`](https://github.com/mikefarah/yq/releases/tag/v4.44.6)

[Compare Source](mikefarah/yq@v4.44.5...v4.44.6)

-   Fixed deleting items in array bug [#&#8203;2027](mikefarah/yq#2027), [#&#8203;2172](mikefarah/yq#2172); Thanks [@&#8203;jandubois](https://github.com/jandubois)
    -   Docker image for armv7 / raspberry pi3, Thanks [@&#8203;brianegge](https://github.com/brianegge)
    -   Fixed no-colors regression [#&#8203;2218](mikefarah/yq#2218)
    -   Fixed various panic scenarios [#&#8203;2211](mikefarah/yq#2211)
    -   Bumped dependencies

</details>

---

### Configuration

📅 **Schedule**: 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:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants