gno icon indicating copy to clipboard operation
gno copied to clipboard

fix(gnovm): include missing field in shallow size calculation + add overflow protection

Open Davphla opened this issue 1 month ago • 2 comments

Fix: #4791 I assume allocPackage constant contains header field size of PkgName.

This also fix a minor security issue concerning GetShallowSize overflow.

Note: In mempackage_type:gnovm/pkg/gnolang/alloc.go:347–364, the shallow size of a package value is estimated by accumulating the memory usage of its FNames, FBlocks, and fBlocksMap fields. is not true anymore. It was remove to be improved in the future: https://github.com/gnolang/gno/pull/4302#discussion_r2315336066.


As well almost none of the gno value defined in constant are equal to the go runtime size. Is it normal? ref: gnovm/pkg/gnolang/alloc_test.go

> go test -run TestAllocSizes -v
=== RUN   TestAllocSizes
=== PAUSE TestAllocSizes
=== CONT  TestAllocSizes
_allocPointer 8
_allocSlice 24
PointerValue{} 32
StructValue{} 176
ArrayValue{} 200
SliceValue{} 40
FuncValue{} 352
MapValue{} 168
BoundMethodValue{} 200
Block{} 520
TypeValue{} 16
TypedValue{} 40
ObjectInfo{} 152
PackageValue{} 272
Constant Name              Defined Value    Actual Size (unsafe.Sizeof)
=============================================================================
_allocPointerValue              40                32  ❌ OFF by 8
_allocStructValue              152               176  ❌ OFF by 24
_allocArrayValue               176               200  ❌ OFF by 24
_allocSliceValue                40                40  ✅ MATCH
_allocFuncValue                312               352  ❌ OFF by 40
_allocMapValue                 144               168  ❌ OFF by 24
_allocBoundMethodValue         176               200  ❌ OFF by 24
_allocBlock                    472               520  ❌ OFF by 48
_allocPackageValue             240               272  ❌ OFF by 32
_allocTypeValue                 16                16  ✅ MATCH
_allocTypedValue                40                40  ✅ MATCH

Edit: Fixed in https://github.com/gnolang/gno/pull/4892/commits/644a808349e70f1c1f70ca9026ab1c185d4f8d77


ref:

  • https://github.com/gnolang/gno/pull/4194
  • https://github.com/gnolang/gno/pull/4302

Davphla avatar Nov 17 '25 16:11 Davphla

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • [ ] IGNORE the bot requirements for this PR (force green CI check)
  • [ ] The pull request description provides enough details
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: Davphla/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
    │       ├── 🔴 At least one of these user(s) reviewed the pull request: [jefft0 leohhhn n0izn0iz notJoon omarsy x1unix] (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
The pull request description provides enough details

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 Not (🔴 Pull request author is a member of the team: core-contributors)
    └── 🟢 Not (🔴 Pull request author is user: dependabot[bot])

Can be checked by

  • team core-contributors

Gno2D2 avatar Nov 17 '25 16:11 Gno2D2

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests.

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Nov 17 '25 16:11 codecov[bot]