Skip to content

Fix soundness issues#74

Merged
shssoichiro merged 3 commits into
rust-av:mainfrom
Shnatsel:ub-poc
May 7, 2026
Merged

Fix soundness issues#74
shssoichiro merged 3 commits into
rust-av:mainfrom
Shnatsel:ub-poc

Conversation

@Shnatsel
Copy link
Copy Markdown
Contributor

@Shnatsel Shnatsel commented May 6, 2026

The first commit adds tests that demonstrate undefined behavior in safe code under miri.

The second commit fixes the issues with minimal API changes. The API could be adjusted to make such issues less likely (e.g. pre-validated fields should not be public and mutable), but this PR only provides a semver-compatible fix.

The third commit updates documentation to more clearly communicate alignment requirements to API users.

Impact analysis

The alignment issue is mostly theoretical and should not impact real-world uses.

The missing field validation results in buffer overflow, but you need to edit the fields after the initial validation pass; I don't expect this to be common in the wild (albeit I haven't verified that), so I don't think it warrants a full-on security advisory, but you might want to get an unsoundness advisory into RustSec with the informational = unsound field.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.40%. Comparing base (e18c52a) to head (7b1eef6).

Files with missing lines Patch % Lines
src/plane/aligned.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
- Coverage   99.53%   99.40%   -0.13%     
==========================================
  Files           7        7              
  Lines         639      668      +29     
==========================================
+ Hits          636      664      +28     
- Misses          3        4       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@FreezyLemon
Copy link
Copy Markdown
Contributor

Good catch on the alignment issue! Public API compatibility is not the biggest concern at the moment since we're breaking semver for the next release anyways (see changes since 0.5.2).

For the other issue, see #61. Unless I missed something, the public API does not expose that particular UB.

@Shnatsel
Copy link
Copy Markdown
Contributor Author

Shnatsel commented May 6, 2026

I believe you are correct - PlaneGeometry is private, as is Plane::new(), so this is not a public-facing soundness issue after all.

@shssoichiro
Copy link
Copy Markdown
Member

Thanks, these fixes seem valid. I'll get them deployed ASAP!

@shssoichiro shssoichiro merged commit 141c74d into rust-av:main May 7, 2026
9 of 11 checks passed
shssoichiro pushed a commit that referenced this pull request May 8, 2026
These should not have been public in the first place. This makes invalid
state between geometry and data impossible (fixing any problems related
to #61) and results in a nicer API overall.

Basically: Plane and AlignedData have safety invariants that depend on
the state of PlaneGeometry when `Plane::new` is called. By both
validating the geometry in its constructor and making it fully
immutable, we ensure that the invariants are always fulfilled.

This also means we can remove the re-validation of geometry (part of
#74) from `Plane::new`.

Changes:
- add getters
- make getters return zeroable scalars over NonZero<T>. With `#[inline]`
this should elide unnecessary `width != 0` checks downstream while
making the API simpler (`plane.width().get()` -> `plane.width()`)
- move data_origin from Plane to geometry, not something downstream
needs without padding awareness (-> `-F padding_api`)
shssoichiro pushed a commit that referenced this pull request May 8, 2026
#74 uncovered that empty data/len==0 returned a dangling pointer that
was not following the same alignment as real allocations. This required
some doc changes and is just not nice in general.

Use `layout.dangling_ptr` instead of the less specific
`NonNull::dangling_ptr` to follow our "usual" alignment rules exactly.
This requires an MSRV bump to 1.95.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants