Skip to content

Commit

Permalink
wolvic: Add frame bounds validation and size checking
Browse files Browse the repository at this point in the history
It does also a small adjustment to create Java WVRSurfaceTexture only
when the SurfaceTexture is also need to be created.
  • Loading branch information
tiagovignatti committed Aug 21, 2023
1 parent 4d5a154 commit ee600a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 7 additions & 2 deletions wolvic/browser/vr/wvr_graphics_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,21 @@ bool WvrGraphicsDelegate::CreateOrResizeWebXrSurface(
webxr_surface_texture_ = gl::SurfaceTexture::Create(webvr_texture_id_);
webxr_surface_texture_->SetFrameAvailableCallback(
std::move(on_webxr_frame_available));
}

if (!j_surface_texture_) {
DCHECK(!j_surface_texture_);
JNIEnv* env = base::android::AttachCurrentThread();
j_surface_texture_ = Java_WVRSurfaceTexture_create(
env,
texture_handle_id_,
webxr_surface_texture_.get()->j_surface_texture());
}

if (size.IsEmpty()) {
// Defer until a new size arrives on a future bounds update.
DVLOG(1) << "Ignore resize, invalid size";
return false;
}

webxr_surface_texture_->SetDefaultBufferSize(size.width(), size.height());
webxr_surface_size_ = size;
return true;
Expand Down
22 changes: 22 additions & 0 deletions wolvic/browser/vr/wvr_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ std::vector<device::mojom::XRViewPtr> CreateViews(
return views;
}

bool ValidateRect(const gfx::RectF& bounds) {
// Bounds should be between 0 and 1, with positive width/height.
// We simply clamp to [0,1], but still validate that the bounds are not NAN.
return !std::isnan(bounds.width()) && !std::isnan(bounds.height()) &&
!std::isnan(bounds.x()) && !std::isnan(bounds.y());
}

} // namespace

WvrManager::WvrManager(WvrApi *wvr_api, WvrGraphicsDelegate* graphics)
Expand Down Expand Up @@ -713,6 +720,21 @@ void WvrManager::UpdateLayerBounds(int16_t frame_index,
const gfx::RectF& left_bounds,
const gfx::RectF& right_bounds,
const gfx::Size& source_size) {
if (!ValidateRect(left_bounds) || !ValidateRect(right_bounds)) {
presentation_receiver_.ReportBadMessage(
"UpdateLayerBounds called with invalid bounds");
ClosePresentationBindings();
return;
}

if (frame_index >= 0 && !webxr_.HaveAnimatingFrame()) {
// The optional UpdateLayerBounds call must happen before SubmitFrame.
presentation_receiver_.ReportBadMessage(
"UpdateLayerBounds called without animating frame");
ClosePresentationBindings();
return;
}

CreateOrResizeWebXrSurface(source_size);
}

Expand Down

0 comments on commit ee600a4

Please sign in to comment.