CNA-BUG-251: BoundingSphere(Vector3 center, float radius) accepts a negative radius, where XNA 4.0 throws ArgumentException

CNA snapshot 009d40f5  ·  Known Issues › Current bugs  ·  source links pinned to 009d40f5

✓

Evidence basis: source-verified at the pinned commit; tests exist (not executed for this page). Claims on this page were checked by reading the CNA source at commit 009d40f5; unless a sentence says otherwise, nothing here was built or executed. Nothing on this page was executed unless the Evidence section says so.

CNA's BoundingSphere(Vector3, float) constructor stores any radius, while XNA 4.0's throws ArgumentException for radius < 0, so a negative radius is silently accepted.

Identifier
CNA-BUG-251
Category
Bug
Subsystem
Math & geometry
Status
Open
Verified against
CNA 009d40f5 (009d40f5dd085c4e674d3479675fac84b12b3e0a)
Severity
Low (a triage suggestion, not a project priority)
Evidence basis
Source-verified: read at TARGET, not executed
Tests touching this area
Yes: see Current tests
Affected contract
CNA::BoundingSphere::BoundingSphere(Vector3 center, float radius) (Microsoft::Xna::Framework::BoundingSphere)

Expected behaviour

XNA 4.0's constructor (read from the decompiled genuine Microsoft.Xna.Framework assembly, BoundingSphere.cs) is if (radius < 0f) throw new ArgumentException(FrameworkResources.NegativeRadius); followed by the two assignments, so a sphere with a negative radius cannot be constructed through it.

Actual behaviour at TARGET

BoundingSphere::BoundingSphere(Vector3, float) in BoundingSphere.cpp is a bare initializer list, Center(center), Radius(radius): it validates nothing, so a caller that passes a negative radius gets a sphere with a negative Radius instead of the exception. Sibling math code already throws sharp-runtime exceptions for invalid arguments (System::ArgumentException in BoundingBox.cpp), so the mechanism exists.

Source locations

Evidence

Checked by reading at 009d40f5; nothing was built or executed for this entry. XNA's guard was read in the decompiled reference (xna4-decomp). Found by the independent adversarial review of the math entries, not by an earlier audit; no published entry covers it (CNA-BUG-070 is about Contains, CNA-BUG-025 about the PlaneIntersectionType Doxygen). The other construction paths of the type (default constructor, the CreateFrom* helpers, Transform) were not examined for the same invariant.

Focused reproduction

No focused reproduction is known. Nothing has been invented here; the evidence above is what exists.

Current tests

BoundingSphereTests.cpp constructs spheres with a positive radius (ConstructorStoresCenterAndRadius); no case passes a negative one.

Regression test

A test that BoundingSphere(Vector3::Zero, -1.0f) throws an ArgumentException-family exception, and that a zero radius still constructs.

Blast radius

Code that builds a BoundingSphere from a computed radius, and XNA code that relies on the constructor's ArgumentException to reject bad input. Correct programs that only pass non-negative radii are unaffected.

Workaround

Validate the radius (radius >= 0) before constructing.

The same subject is explained at several altitudes. These are the neighbouring pages at each one.

User guide
Math types
Known issues
Bug index