glocalfileinfo: Ensure we always sniff some data to get the content type

In case the XDG database is not initialized yet we may try to sniff a
0-length data, making our content-type routines to mark non-empty files
as `application/x-zerosize`.

This is wrong, so in case the sniff size is not set, let's just
try to read the default value. To avoid false-application/x-zerosize
results (that are not something we want as per legacy assumptions).

See: https://bugzilla.gnome.org/show_bug.cgi?id=755795

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2742
This commit is contained in:
Marco Trevisan (Treviño)
2022-09-13 05:38:21 +02:00
parent 0d823aa926
commit 846e68befd
2 changed files with 43 additions and 2 deletions

View File

@@ -1388,7 +1388,7 @@ get_content_type (const char *basename,
int fd, errsv;
sniff_length = _g_unix_content_type_get_sniff_len ();
if (sniff_length > 4096)
if (sniff_length == 0 || sniff_length > 4096)
sniff_length = 4096;
#ifdef O_NOATIME