summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-11-18 10:55:28 +0000
committerRichard Hughes <richard@hughsie.com>2016-11-18 14:58:57 +0000
commit538da2d8e078de3ec7f38b56e4ddadd1da401c4d (patch)
treeadd57e88b8dcdb5734add9ab56a0dcda38812ef8
parentb4526187ea1353da4b4401c8181e180f0e50482b (diff)
downloadappstream-glib-538da2d8e078de3ec7f38b56e4ddadd1da401c4d.tar.gz
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.
-rw-r--r--libappstream-glib/as-yaml.c14
1 files 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