mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 11:45:25 +00:00
udpsrc: sanity check size of available packet data for reading to avoid memory waste
On Windows and OS/X, _get_available_bytes() may not return the size of the next pending packet, but the size of all pending packets in the kernel-side buffer, which might be rather large depending on configuration. Sanity-check the size returned by _get_available_bytes() to make sure we never allocate more memory than the max. size for a packet, if it's an IPv4 socket. https://bugzilla.gnome.org/show_bug.cgi?id=610364
This commit is contained in:
parent
ad2f74afbc
commit
cf1f6aff0d
1 changed files with 8 additions and 0 deletions
|
@ -116,6 +116,9 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* not 100% correct, but a good upper bound for memory allocation purposes */
|
||||||
|
#define MAX_IPV4_UDP_PACKET_SIZE (65536 - 8)
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (udpsrc_debug);
|
GST_DEBUG_CATEGORY_STATIC (udpsrc_debug);
|
||||||
#define GST_CAT_DEFAULT (udpsrc_debug)
|
#define GST_CAT_DEFAULT (udpsrc_debug)
|
||||||
|
|
||||||
|
@ -442,6 +445,11 @@ retry:
|
||||||
no_select:
|
no_select:
|
||||||
GST_LOG_OBJECT (udpsrc, "ioctl says %d bytes available", (int) readsize);
|
GST_LOG_OBJECT (udpsrc, "ioctl says %d bytes available", (int) readsize);
|
||||||
|
|
||||||
|
/* sanity check value from _get_available_bytes(), which might be as
|
||||||
|
* large as the kernel-side buffer on some operating systems */
|
||||||
|
if (g_socket_get_family (udpsrc->used_socket) == G_SOCKET_FAMILY_IPV4)
|
||||||
|
readsize = MIN (MAX_IPV4_UDP_PACKET_SIZE, readsize);
|
||||||
|
|
||||||
ret = GST_BASE_SRC_CLASS (parent_class)->alloc (GST_BASE_SRC_CAST (udpsrc),
|
ret = GST_BASE_SRC_CLASS (parent_class)->alloc (GST_BASE_SRC_CAST (udpsrc),
|
||||||
-1, readsize, &outbuf);
|
-1, readsize, &outbuf);
|
||||||
if (ret != GST_FLOW_OK)
|
if (ret != GST_FLOW_OK)
|
||||||
|
|
Loading…
Reference in a new issue