Skip to content

fix(gnovm): avoid panic on assertion over nil slice#5780

Open
Villaquiranm wants to merge 8 commits into
gnolang:masterfrom
Villaquiranm:fix/5776
Open

fix(gnovm): avoid panic on assertion over nil slice#5780
Villaquiranm wants to merge 8 commits into
gnolang:masterfrom
Villaquiranm:fix/5776

Conversation

@Villaquiranm

Copy link
Copy Markdown
Contributor

closes #5776

@github-actions github-actions Bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Jun 4, 2026
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jun 4, 2026
@Gno2D2

Gno2D2 commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)
🟢 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: Villaquiranm/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🟢 Requirement satisfied
└── 🟢 If
    ├── 🟢 Condition
    │   └── 🟢 Or
    │       ├── 🟢 User davd-gzl already reviewed PR 5780 with state APPROVED
    │       ├── 🔴 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🟢 Then
        └── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread gnovm/pkg/gnolang/op_expressions.go Outdated
Comment on lines +790 to +793
if xv.V != nil {
sv := xv.V.(*SliceValue)
m.incrCPU(OpCPUSlopeConvertRunesStr * int64(sv.GetLength()))
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a philosophical question but should we increment the CPU for converting an empty string (0 length) ?

@davd-gzl davd-gzl self-requested a review June 5, 2026 15:40
@Gno2D2 Gno2D2 removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jun 5, 2026

@omarsy omarsy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks correct — a nil slice has length 0, so skipping the incrCPU is gas-neutral, and ConvertTo handles the nil value fine downstream. Two small suggestions inline: use the nil-safe GetLength() accessor instead of guarding the assertion, and consider moving the regression test to gnovm/tests/files/ as a filetest. Neither blocks merging.

[AI] This review was drafted with AI assistance (Claude).

Comment thread gnovm/pkg/gnolang/op_expressions.go Outdated
Comment on lines +794 to +797
if xv.V != nil {
sv := xv.V.(*SliceValue)
m.incrCPU(OpCPUSlopeConvertRunesStr * int64(sv.GetLength()))
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: TypedValue.GetLength() already handles V == nil (returns 0 for slices), so this can be a one-liner without the assertion:

m.incrCPU(OpCPUSlopeConvertRunesStr * int64(xv.GetLength()))

This also mirrors the string→runes branch above, which is nil-safe for the same reason (xv.GetString() returns "" on nil V). Behavior is identical: a nil slice has length 0, so it charges 0 gas either way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here thanks for the review: 8bec3e7

@@ -0,0 +1,23 @@
gno run .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit on placement: this txtar runs gno run . but lives in testdata/test/, where every other script exercises the gno test subcommand (the testdata subdirs are grouped per subcommand). Since this is a VM-behavior regression rather than a CLI one, the canonical home would be a filetest in gnovm/tests/files/ with an // Output: comment — lighter weight (runs under TestFiles instead of spinning up the CLI), and the issue body is already written in that format, so it converts directly.

Optional while you're at it: only the []MyRune line actually reaches the buggy branch ([]MyByte never enters the Int32Kind gas path). Adding a plain var r []rune; _ = string(r) would document that the bug wasn't specific to declared types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed here 8bec3e7

For the change on the type I could do it but this file references Golang tests so I don't know if a good idea to modify it let me know if you still want to do the change and I'll do it

@thehowl thehowl added the a/vm GnoVM, Security, Runtime team label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a/vm GnoVM, Security, Runtime team 📦 🤖 gnovm Issues or PRs gnovm related

Projects

Development

Successfully merging this pull request may close these issues.

Gno errors on string([]MyByte) where Go runs clean

5 participants