mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-21 08:28:53 +02:00
gbytearray: Do not accept too large byte arrays
GByteArray uses guint for storing the length of the byte array, but it also has a constructor (g_byte_array_new_take) that takes length as a gsize. gsize may be larger than guint (64 bits for gsize vs 32 bits for guint). It is possible to call the function with a value greater than G_MAXUINT, which will result in silent length truncation. This may happen as a result of unreffing GBytes into GByteArray, so rather be loud about it. (Test case tweaked by Philip Withnall.)
This commit is contained in:
committed by
Philip Withnall
parent
efe49e46cf
commit
acb7b0ec69
@@ -2261,6 +2261,10 @@ g_byte_array_steal (GByteArray *array,
|
||||
* Create byte array containing the data. The data will be owned by the array
|
||||
* and will be freed with g_free(), i.e. it could be allocated using g_strdup().
|
||||
*
|
||||
* Do not use it if @len is greater than %G_MAXUINT. #GByteArray
|
||||
* stores the length of its data in #guint, which may be shorter than
|
||||
* #gsize.
|
||||
*
|
||||
* Since: 2.32
|
||||
*
|
||||
* Returns: (transfer full): a new #GByteArray
|
||||
@@ -2272,6 +2276,8 @@ g_byte_array_new_take (guint8 *data,
|
||||
GByteArray *array;
|
||||
GRealArray *real;
|
||||
|
||||
g_return_val_if_fail (len <= G_MAXUINT, NULL);
|
||||
|
||||
array = g_byte_array_new ();
|
||||
real = (GRealArray *)array;
|
||||
g_assert (real->data == NULL);
|
||||
|
Reference in New Issue
Block a user