Skip to content

WIP fix(gnovm): clamp bogus make(map, n) hint#5770

Open
ltzmaxwell wants to merge 4 commits into
gnolang:masterfrom
ltzmaxwell:fix/map-hint-clamp
Open

WIP fix(gnovm): clamp bogus make(map, n) hint#5770
ltzmaxwell wants to merge 4 commits into
gnolang:masterfrom
ltzmaxwell:fix/map-hint-clamp

Conversation

@ltzmaxwell

@ltzmaxwell ltzmaxwell commented Jun 3, 2026

Copy link
Copy Markdown
Contributor
  • Before: make(map[K]V, n) panicked with the internal "addition overflow" when n was large enough that allocMap + allocMapItem*n overflowed int64; after: such hints (and negatives) silently clamp to 0, matching Go's makemap verbatim.
  • Allocator.NewMap (gnovm/pkg/gnolang/alloc.go) clamps size < 0 || int64(size) > maxMapHint to 0 before AllocateMap. maxMapHint = (math.MaxInt64 - allocMap) / allocMapItem is the largest hint whose preallocation cost still fits in int64 (~1.15e17).
  • Realistic over-budget hints (e.g. make(map, 10_000_000_000)) are well below maxMapHint, so the clamp doesn't fire — the full byte cost is charged and Allocate panics with "allocation limit exceeded" at the make() line, keeping the diagnostic clean.
  • Covered by filetest gnovm/tests/files/make19.gno (negative + MaxInt hints don't panic; map stays usable) and TestNewMapHintBoundary in alloc_test.go (full byte charge at pivot-1/pivot; clamp to allocMap at pivot+1/MaxInt/-1).

@Gno2D2

Gno2D2 commented Jun 3, 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)

☑️ 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: ltzmaxwell/gno)

Then

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

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

@ltzmaxwell ltzmaxwell changed the title refactor(gnovm): simplify map-hint clamp to a constant; add boundary test fix(gnovm): clamp bogus make(map, n) hint to 0 instead of panicking Jun 3, 2026
@ltzmaxwell ltzmaxwell changed the title fix(gnovm): clamp bogus make(map, n) hint to 0 instead of panicking WIP fix(gnovm): clamp bogus make(map, n) hint Jun 3, 2026
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@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.

3 participants