Skip to content

Commit 655bca1

Browse files
calvarisaperezdc
authored andcommitted
[GStreamer] Do not access a null GstStructure https://bugs.webkit.org/show_bug.cgi?id=279972 Reviewed by Philippe Normand. Stats can be null in some sinks so we avoid accessing them in that case. For the same prize we protect the access to null structures in the GstStructure accessors. * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::gstStructureGet): (WebCore::gstStructureGetString): (WebCore::gstStructureGetName): * Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::updateVideoSinkStatistics): Canonical link: https://commits.webkit.org/283974@main Canonical link: https://commits.webkit.org/282416.111@webkitglib/2.46
1 parent 3f11c27 commit 655bca1

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,11 @@ std::optional<T> gstStructureGet(const GstStructure* structure, ASCIILiteral key
10191019
template<typename T>
10201020
std::optional<T> gstStructureGet(const GstStructure* structure, StringView key)
10211021
{
1022+
if (!structure) {
1023+
ASSERT_NOT_REACHED_WITH_MESSAGE("tried to access a field of a null GstStructure");
1024+
return std::nullopt;
1025+
}
1026+
10221027
T value;
10231028
auto strKey = key.toStringWithoutCopying();
10241029
if constexpr(std::is_same_v<T, int>) {
@@ -1063,16 +1068,31 @@ template std::optional<bool> gstStructureGet(const GstStructure*, StringView key
10631068

10641069
StringView gstStructureGetString(const GstStructure* structure, ASCIILiteral key)
10651070
{
1071+
if (!structure) {
1072+
ASSERT_NOT_REACHED_WITH_MESSAGE("tried to access a field of a null GstStructure");
1073+
return { };
1074+
}
1075+
10661076
return gstStructureGetString(structure, StringView { key });
10671077
}
10681078

10691079
StringView gstStructureGetString(const GstStructure* structure, StringView key)
10701080
{
1081+
if (!structure) {
1082+
ASSERT_NOT_REACHED_WITH_MESSAGE("tried to access a field of a null GstStructure");
1083+
return { };
1084+
}
1085+
10711086
return StringView::fromLatin1(gst_structure_get_string(structure, static_cast<const char*>(key.rawCharacters())));
10721087
}
10731088

10741089
StringView gstStructureGetName(const GstStructure* structure)
10751090
{
1091+
if (!structure) {
1092+
ASSERT_NOT_REACHED_WITH_MESSAGE("tried to access a field of a null GstStructure");
1093+
return { };
1094+
}
1095+
10761096
return StringView::fromLatin1(gst_structure_get_name(structure));
10771097
}
10781098

Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4301,6 +4301,9 @@ bool MediaPlayerPrivateGStreamer::updateVideoSinkStatistics()
43014301

43024302
GUniqueOutPtr<GstStructure> stats;
43034303
g_object_get(m_videoSink.get(), "stats", &stats.outPtr(), nullptr);
4304+
if (!stats)
4305+
return false;
4306+
43044307
auto totalVideoFrames = gstStructureGet<uint64_t>(stats.get(), "rendered"_s);
43054308
auto droppedVideoFrames = gstStructureGet<uint64_t>(stats.get(), "dropped"_s);
43064309

0 commit comments

Comments
 (0)