Skip to content

Conversation

@Davphla
Copy link
Contributor

@Davphla Davphla commented Nov 17, 2025

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: #4302 (comment).

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

ref:

@Gno2D2
Copy link
Collaborator

Gno2D2 commented Nov 17, 2025

🛠 PR Checks Summary

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

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 not 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
    └── 🔴 Else
        └── 🔴 And
            ├── 🟢 This label is applied to pull request: review/triage-pending
            └── 🔴 On no 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
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

@Davphla Davphla changed the title fix(alloc): Include pckgName field size in PackageValue ShallowSize fix(alloc): Include missing pckgName field size in PackageValue shallow size allocation calculation Nov 17, 2025
@Davphla Davphla changed the title fix(alloc): Include missing pckgName field size in PackageValue shallow size allocation calculation fix(gnovm): Include missing pckgName field size in PackageValue shallow size allocation calculation Nov 17, 2025
@Davphla Davphla changed the title fix(gnovm): Include missing pckgName field size in PackageValue shallow size allocation calculation fix(gnovm): Include missing field in shallow size calculation for PackageValue Nov 17, 2025
@Davphla Davphla changed the title fix(gnovm): Include missing field in shallow size calculation for PackageValue fix(gnovm): include missing field in shallow size calculation for PackageValue Nov 17, 2025
@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Davphla Davphla marked this pull request as ready for review November 21, 2025 13:44
@Davphla Davphla moved this from In progress to NEED PEER REVIEW (INTERNAL) in FlashorgSprint: Gnocore Minicrew 🥷 Nov 21, 2025
@Davphla Davphla changed the title fix(gnovm): include missing field in shallow size calculation for PackageValue fix(gnovm): include missing field in shallow size calculation + add overflow protection Nov 21, 2025
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Nov 21, 2025
@Kouteki Kouteki requested a review from ltzmaxwell November 24, 2025 11:09
@Kouteki Kouteki moved this from Triage to In Review in 🧙‍♂️gno.land core team Nov 24, 2025
@Kouteki Kouteki requested a review from jaekwon November 29, 2025 10:25
@Davphla Davphla moved this from NEED PEER REVIEW (INTERNAL) to Waiting for core Review in FlashorgSprint: Gnocore Minicrew 🥷 Nov 29, 2025
Copy link
Contributor

@Villaquiranm Villaquiranm left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 🤖 gnovm Issues or PRs gnovm related review/triage-pending PRs opened by external contributors that are waiting for the 1st review

Projects

Status: No status
Status: In Review

Development

Successfully merging this pull request may close these issues.

Missing inclusion of pckgName field in shallow size allocation calculation

4 participants