From 538da2d8e078de3ec7f38b56e4ddadd1da401c4d Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 18 Nov 2016 10:55:28 +0000 Subject: Detect invalid files in the libyaml read handler If non-gzipped files are saved as .yml.gz they are seeked by the GInputStream GZlibDecompressor which fails. This can happen when the user is connected to a badly configured captive portal and the downloaded 'gzipped yaml file' is actually the captive portal HTML login page. Detect this and handle the error the best we can given the libyaml API constraints. This probably fixes bugs like https://github.com/hughsie/fwupd/issues/70 and similar bugs in gnome-software. --- libappstream-glib/as-yaml.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libappstream-glib/as-yaml.c b/libappstream-glib/as-yaml.c index 3b03fc3..76cab57 100644 --- a/libappstream-glib/as-yaml.c +++ b/libappstream-glib/as-yaml.c @@ -428,12 +428,14 @@ as_yaml_read_handler_cb (void *data, size_t *size_read) { GInputStream *stream = G_INPUT_STREAM (data); - *size_read = (gsize) g_input_stream_read (stream, - buffer, - (gsize) - size, - NULL, - NULL); + gssize len = g_input_stream_read (stream, + buffer, + (gsize) size, + NULL, + NULL); + if (len < 0) + return 0; + *size_read = (gsize) len; return 1; } #endif -- cgit v1.2.1