webxr: Add some missing internal checks/validation (#33318)

* Ensure depthFar is non-negative

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Properly append default features in requestSession

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Ensure XRRigidTransform init members have finite values

Signed-off-by: Daniel Adams <msub2official@gmail.com>

---------

Signed-off-by: Daniel Adams <msub2official@gmail.com>
This commit is contained in:
Daniel Adams 2024-09-05 03:39:27 +00:00 committed by GitHub
parent aadc212b95
commit 75c7712905
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 35 additions and 40 deletions

View file

@ -83,6 +83,26 @@ impl XRRigidTransform {
)));
}
if !position.x.is_finite() ||
!position.y.is_finite() ||
!position.z.is_finite() ||
!position.w.is_finite()
{
return Err(Error::Type(
"Position must not contain non-finite values".into(),
));
}
if !orientation.x.is_finite() ||
!orientation.y.is_finite() ||
!orientation.z.is_finite() ||
!orientation.w.is_finite()
{
return Err(Error::Type(
"Orientation must not contain non-finite values".into(),
));
}
let translate = Vector3D::new(position.x as f32, position.y as f32, position.z as f32);
let rotate = Rotation3D::unit_quaternion(
orientation.x as f32,

View file

@ -709,11 +709,16 @@ impl XRSessionMethods for XRSession {
pending.set_depth_near(near);
}
if let Some(far) = init.depthFar {
let mut far = *far;
// Step 9 from #apply-the-pending-render-state
// this may need to be changed if backends wish to impose
// further constraints
// currently the maximum is infinity, so we do nothing
pending.set_depth_far(*far);
// currently the maximum is infinity, so just check that
// the value is non-negative
if far < 0. {
far = 0.;
}
pending.set_depth_far(far);
}
if let Some(fov) = init.inlineVerticalFieldOfView {
let mut fov = *fov;

View file

@ -187,8 +187,6 @@ impl XRSystemMethods for XRSystem {
let mut optional_features = vec![];
let cx = GlobalScope::get_cx();
// We are supposed to include "viewer" and on immersive devices "local"
// by default here, but this is handled directly in requestReferenceSpace()
if let Some(ref r) = init.requiredFeatures {
for feature in r {
unsafe {
@ -222,6 +220,14 @@ impl XRSystemMethods for XRSystem {
}
}
if !required_features.contains(&"viewer".to_string()) {
required_features.push("viewer".to_string());
}
if !required_features.contains(&"local".to_string()) && mode != XRSessionMode::Inline {
required_features.push("local".to_string());
}
let init = SessionInit {
required_features,
optional_features,