From 57457913455785adf862bd9ec976fdf43b548dd9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20D=C3=B8rum?= Date: Wed, 31 Aug 2022 14:23:59 +0200 Subject: [PATCH] gstpluginloader: Don't hang on short reads/writes If read_one or write_one was called but the stream closed before it could read/write a whole packet, read_one/write_one would hang indefinitely, consuming 100% CPU. This commit fixes that by treating a short read/write as an error. Part-of: --- subprojects/gstreamer/gst/gstpluginloader.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/subprojects/gstreamer/gst/gstpluginloader.c b/subprojects/gstreamer/gst/gstpluginloader.c index fb8b45c..8dc96fd 100644 --- a/subprojects/gstreamer/gst/gstpluginloader.c +++ b/subprojects/gstreamer/gst/gstpluginloader.c @@ -810,6 +810,9 @@ write_one (GstPluginLoader * l) continue; /* Failed to write -> child died */ goto fail_and_cleanup; + } else if (G_UNLIKELY (res == 0)) { + /* FD closed -> child died */ + goto fail_and_cleanup; } to_write -= res; out += res; @@ -1074,6 +1077,9 @@ read_one (GstPluginLoader * l) continue; GST_LOG ("Failed reading packet header"); return FALSE; + } else if (G_UNLIKELY (res == 0)) { + GST_LOG ("Failed reading packet header: Unexpected EOF"); + return FALSE; } to_read -= res; in += res; @@ -1111,6 +1117,9 @@ read_one (GstPluginLoader * l) continue; GST_ERROR ("Packet payload read failed"); return FALSE; + } else if (G_UNLIKELY (res == 0)) { + GST_ERROR ("Packet payload read failed: Unexpected EOF"); + return FALSE; } to_read -= res; in += res; -- 2.7.4