fix(hle): saturate storage quota conversion #337

Closed
CesarLopesO wants to merge 4 commits from upstream-pr/337 into main
CesarLopesO commented 2026-11-24 02:23:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by CesarLopesO on 2026-11-24T02:23:27Z.


Summary

  • Replace the left shift used to convert the manifest's persistent storage quota from MB to bytes with saturating multiplication.
  • Prevent oversized SizeMB values from silently overflowing during conversion.
  • Add a regression test covering the largest representable MB value and the first value above that limit.

Validation

  • rustfmt --edition 2024 --check crates/victory-hle/src/runtime.rs — passed
  • git diff --check — passed
  • cargo check --locked -p victory-hle --tests --target x86_64-pc-windows-gnu — passed
  • cargo test --locked -p victory-hle --no-run --target x86_64-pc-windows-gnu — passed

Test limitation

cargo test --locked -p victory-hle runtime::tests could not reach the tests on the current Linux main branch because compilation fails first in crates/victory-gpu/src/resource.rs with E0425: cannot find function host_resource.

This is the existing Linux build issue tracked in #90; related Linux compatibility changes are proposed separately in #235. This PR only changes crates/victory-hle/src/runtime.rs.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573183635 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/337). Originally posted by [CesarLopesO](https://github.com/CesarLopesO) on 2026-11-24T02:23:27Z. --- ## Summary - Replace the left shift used to convert the manifest's persistent storage quota from MB to bytes with saturating multiplication. - Prevent oversized `SizeMB` values from silently overflowing during conversion. - Add a regression test covering the largest representable MB value and the first value above that limit. ## Validation - rustfmt --edition 2024 --check crates/victory-hle/src/runtime.rs — passed - git diff --check — passed - cargo check --locked -p victory-hle --tests --target x86_64-pc-windows-gnu — passed - cargo test --locked -p victory-hle --no-run --target x86_64-pc-windows-gnu — passed ## Test limitation `cargo test --locked -p victory-hle runtime::tests` could not reach the tests on the current Linux `main` branch because compilation fails first in `crates/victory-gpu/src/resource.rs` with `E0425: cannot find function host_resource`. This is the existing Linux build issue tracked in #90; related Linux compatibility changes are proposed separately in #235. This PR only changes `crates/victory-hle/src/runtime.rs`.
jeremygold02 commented 2026-11-24 06:55:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:21:51Z.


Tested PR #337 at head 6922a81d615f4e7a55b6f488a0dc704351568a13 (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at 6922a81d615f4e7a55b6f488a0dc704351568a13.

  • cargo test --locked -p victory-hle storage_quota_saturates_when_megabytes_exceed_u64_bytes — FAILED (exit 101); detail: error[E0689]: can't call method saturating_mul on ambiguous numeric type {integer} | error: could not compile victory-hle (lib) due to 1 previous error.

Behavior covered: Checks storage quota conversion saturates when megabytes exceed the u64 byte range.
Code: crates/victory-hle/src/runtime.rs

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121949625 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/337#issuecomment-7121949625). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:21:51Z. --- Tested PR #337 at head `6922a81d615f4e7a55b6f488a0dc704351568a13` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `6922a81d615f4e7a55b6f488a0dc704351568a13`. - `cargo test --locked -p victory-hle storage_quota_saturates_when_megabytes_exceed_u64_bytes` — FAILED (exit 101); detail: error[E0689]: can't call method `saturating_mul` on ambiguous numeric type `{integer}` | error: could not compile `victory-hle` (lib) due to 1 previous error. Behavior covered: Checks storage quota conversion saturates when megabytes exceed the u64 byte range. Code: [crates/victory-hle/src/runtime.rs](https://github.com/Marvisak/VIctory/blob/6922a81d615f4e7a55b6f488a0dc704351568a13/crates/victory-hle/src/runtime.rs)
mercuryVM commented 2026-11-24 09:05:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T08:21:56Z.

Review: CHANGES_REQUESTED


Tested 6922a81 on Windows 11, RTX 5070, MSVC: victory-hle fails to compile:

error[E0689]: can't call method `saturating_mul` on ambiguous numeric type `{integer}`
   --> crates\victory-hle\src\runtime.rs:104:52
    |
104 |             storage_bytes: storage_mb.unwrap_or(0).saturating_mul(1024 * 1024),

storage_mb.unwrap_or(0) leaves the literal's type undetermined at the point of the method call. Annotate it: storage_mb.unwrap_or(0u64).saturating_mul(1 << 20), or .map_or(0, |mb: u64| mb.saturating_mul(1 << 20)). With that, the saturating conversion and the boundary test look right.

The elements hunk is only rustfmt reflow of an unrelated line. Dropping it would keep the diff focused, especially since #359 also touches that function.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6035839264 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/337#pullrequestreview-6035839264). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T08:21:56Z. **Review:** CHANGES_REQUESTED --- Tested 6922a81 on Windows 11, RTX 5070, MSVC: **`victory-hle` fails to compile:** ``` error[E0689]: can't call method `saturating_mul` on ambiguous numeric type `{integer}` --> crates\victory-hle\src\runtime.rs:104:52 | 104 | storage_bytes: storage_mb.unwrap_or(0).saturating_mul(1024 * 1024), ``` `storage_mb.unwrap_or(0)` leaves the literal's type undetermined at the point of the method call. Annotate it: `storage_mb.unwrap_or(0u64).saturating_mul(1 << 20)`, or `.map_or(0, |mb: u64| mb.saturating_mul(1 << 20))`. With that, the saturating conversion and the boundary test look right. The `elements` hunk is only rustfmt reflow of an unrelated line. Dropping it would keep the diff focused, especially since #359 also touches that function. AI-assisted (Claude Code).
CesarLopesO commented 2026-11-24 11:04:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by CesarLopesO on 2026-11-24T10:57:36Z.


Updated the PR with the explicit u64 parsing fix and the rustfmt adjustments.

Additional validation on Debian 13:

  • rustfmt --edition 2024 --check crates/victory-hle/src/runtime.rs — passed.
  • git diff --check — passed.
  • Windows GNU cross-compilation with cargo check --tests — passed.
  • cargo test --no-run for victory-hle on the Windows GNU target — passed; test binaries were compiled successfully, but not executed.

Native Linux test execution remains blocked by the unrelated host_resource E0425 error in victory-gpu (#90).

Could you please review the updated commit?

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129468751 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/337#issuecomment-7129468751). Originally posted by [CesarLopesO](https://github.com/CesarLopesO) on 2026-11-24T10:57:36Z. --- Updated the PR with the explicit `u64` parsing fix and the rustfmt adjustments. Additional validation on Debian 13: - `rustfmt --edition 2024 --check crates/victory-hle/src/runtime.rs` — passed. - `git diff --check` — passed. - Windows GNU cross-compilation with `cargo check --tests` — passed. - `cargo test --no-run` for `victory-hle` on the Windows GNU target — passed; test binaries were compiled successfully, but not executed. Native Linux test execution remains blocked by the unrelated `host_resource` E0425 error in `victory-gpu` (#90). Could you please review the updated commit?
mercuryVM commented 2026-11-24 13:01:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:56:20Z.

Review: APPROVED


Re-tested 5cf259e on Windows 11, RTX 5070, MSVC: it now compiles, and cargo test -p victory-hle 88 passed, including storage_quota_saturates_when_megabytes_exceed_u64_bytes.

  • This addresses my earlier review (E0689 on an unsuffixed saturating_mul): parse::<u64>() fixes the integer type, so saturating_mul(1024 * 1024) resolves, and a SizeMB above u64::MAX / 2^20 gives u64::MAX instead of wrapping as << 20 did.
  • The test pins both sides of the boundary, the exact limit and one past it.
  • The entity-decoding hunk is a rustfmt reflow only.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6039569407 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/337#pullrequestreview-6039569407). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T12:56:20Z. **Review:** APPROVED --- Re-tested 5cf259e on Windows 11, RTX 5070, MSVC: it now compiles, and `cargo test -p victory-hle` 88 passed, including `storage_quota_saturates_when_megabytes_exceed_u64_bytes`. - This addresses my earlier review (E0689 on an unsuffixed `saturating_mul`): `parse::<u64>()` fixes the integer type, so `saturating_mul(1024 * 1024)` resolves, and a `SizeMB` above `u64::MAX / 2^20` gives `u64::MAX` instead of wrapping as `<< 20` did. - The test pins both sides of the boundary, the exact limit and one past it. - The entity-decoding hunk is a rustfmt reflow only. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 00:05:24 +00:00
Marvisak commented 2026-11-25 00:06:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:02:17Z.


Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current).

Saturates the SizeMB to bytes conversion, which only matters for a manifest quota above 2^44 MB; cannot occur. The rest is reformatting, and the test was never run (cross-compiled only).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148067623 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/337#issuecomment-7148067623). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:02:17Z. --- Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current). Saturates the SizeMB to bytes conversion, which only matters for a manifest quota above 2^44 MB; cannot occur. The rest is reformatting, and the test was never run (cross-compiled only). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!337
No description provided.