Truly independent web browser
LibCompositing: Don't believe forged presented frame records
Zaggy10245f952adc2d59
diff --git a/Libraries/LibCompositing/Video/VideoFramePresentationPage.cpp b/Libraries/LibCompositing/Video/VideoFramePresentationPage.cppindex 9ea2b27756f..ddf35bb26e5 100644--- a/Libraries/LibCompositing/Video/VideoFramePresentationPage.cpp+++ b/Libraries/LibCompositing/Video/VideoFramePresentationPage.cpp@@ -7,6 +7,7 @@#include <LibCompositing/Video/VideoFramePresentationPage.h>#include <LibIPC/Decoder.h>#include <LibIPC/Encoder.h>+#include <LibMediaCodecs/Limits.h>namespace Compositing {@@ -91,7 +92,12 @@ void VideoFramePresentationPage::publish_presented_frame(PresentedFrame const& pOptional<VideoFramePresentationPage::PresentedFrame> VideoFramePresentationPage::presented_frame() const{- return m_shared_state->presented_frame.read();+ auto presented_frame = m_shared_state->presented_frame.read();+ if (!presented_frame.has_value())+ return {};+ if (presented_frame->width > Media::MAX_VIDEO_FRAME_DIMENSION || presented_frame->height > Media::MAX_VIDEO_FRAME_DIMENSION)+ return {};+ return presented_frame;}VideoFramePresentationPage::ReleaseResult VideoFramePresentationPage::release_hold_if_current(u64 generation)diff --git a/Libraries/LibCompositing/Video/VideoFramePresentationPage.h b/Libraries/LibCompositing/Video/VideoFramePresentationPage.hindex 3353a95a8b9..4668c31f6cf 100644--- a/Libraries/LibCompositing/Video/VideoFramePresentationPage.h+++ b/Libraries/LibCompositing/Video/VideoFramePresentationPage.h@@ -12,6 +12,7 @@#include <AK/Optional.h>#include <AK/RefCounted.h>#include <AK/SeqLock.h>+#include <AK/SharedMemoryValue.h>#include <AK/Time.h>#include <LibCompositing/Export.h>#include <LibCore/AnonymousBuffer.h>@@ -52,8 +53,8 @@ public:u64 generation { 0 };u64 presented_frame_count { 0 };u64 dropped_frame_count { 0 };- AK::Duration media_time { AK::Duration::zero() };- MonotonicTime presentation_time;+ SharedMemoryValue<AK::Duration> media_time;+ SharedMemoryValue<MonotonicTime> presentation_time;u32 width { 0 };u32 height { 0 };};diff --git a/Tests/LibCompositing/TestVideoFrameHold.cpp b/Tests/LibCompositing/TestVideoFrameHold.cppindex 9a1d67b1357..59c87014fd6 100644--- a/Tests/LibCompositing/TestVideoFrameHold.cpp+++ b/Tests/LibCompositing/TestVideoFrameHold.cpp@@ -4,6 +4,8 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <AK/BitCast.h>+#include <AK/SharedMemoryValue.h>#include <AK/Vector.h>#include <LibCompositing/Video/VideoFrameHold.h>#include <LibCompositing/Video/VideoFramePresentationPage.h>@@ -103,3 +105,27 @@ TEST_CASE(an_unsent_hold_on_a_replaced_generation_is_released_through_the_compos}EXPECT_EQ(released_through_compositor, (Vector<u64> { 1 }));}++// The Compositor writes the presented frame record that WebContent reads, so WebContent must not believe a time that+// is not a Duration or dimensions no decoded frame could have.+TEST_CASE(forged_presented_frames_are_not_believed)+{+ auto pages = create_page_pair();++ VideoFramePresentationPage::PresentedFrame presented_frame;+ presented_frame.presented_frame_count = 1;+ presented_frame.width = 1920;+ presented_frame.height = 1080;+ SharedMemoryCodec<AK::Duration>::Representation forged_time { 3, 2'000'000'000 };+ presented_frame.media_time = bit_cast<SharedMemoryValue<AK::Duration>>(forged_time);+ pages.compositor->publish_presented_frame(presented_frame);++ auto read_back = pages.web_content->presented_frame();+ EXPECT(read_back.has_value());+ EXPECT_EQ(static_cast<AK::Duration>(read_back->media_time), AK::Duration::zero());+ EXPECT_EQ(read_back->width, 1920u);++ presented_frame.width = 1u << 20;+ pages.compositor->publish_presented_frame(presented_frame);+ EXPECT(!pages.web_content->presented_frame().has_value());+}