Skip to content

Commit

Permalink
Detect invalid files in the libyaml read handler
Browse files Browse the repository at this point in the history
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 fwupd/fwupd#70
and similar bugs in gnome-software.
  • Loading branch information
hughsie committed Nov 18, 2016
1 parent b452618 commit 538da2d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions libappstream-glib/as-yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 538da2d

Please sign in to comment.