mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 03:46:17 +01:00
gvdb-reader: refuse to open file with small header
Clean up the logic for dealing with invalid headers and include the case where the file is too small to contain a fully-formed header.
This commit is contained in:
parent
4e77b52ad8
commit
ae3d42c60f
@ -136,6 +136,7 @@ new_from_data (const void *data,
|
||||
const char *filename,
|
||||
GError **error)
|
||||
{
|
||||
const struct gvdb_header *header;
|
||||
GvdbTable *file;
|
||||
|
||||
file = g_slice_new0 (GvdbTable);
|
||||
@ -147,9 +148,10 @@ new_from_data (const void *data,
|
||||
file->unref_user_data = unref;
|
||||
file->user_data = user_data;
|
||||
|
||||
if (sizeof (struct gvdb_header) <= file->size)
|
||||
{
|
||||
const struct gvdb_header *header = (gpointer) file->data;
|
||||
if (file->size < sizeof (struct gvdb_header))
|
||||
goto invalid;
|
||||
|
||||
header = (gpointer) file->data;
|
||||
|
||||
if (header->signature[0] == GVDB_SIGNATURE0 &&
|
||||
header->signature[1] == GVDB_SIGNATURE1 &&
|
||||
@ -162,24 +164,24 @@ new_from_data (const void *data,
|
||||
file->byteswapped = TRUE;
|
||||
|
||||
else
|
||||
{
|
||||
goto invalid;
|
||||
|
||||
gvdb_table_setup_root (file, &header->root);
|
||||
|
||||
return file;
|
||||
|
||||
invalid:
|
||||
if (filename)
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
|
||||
"%s: invalid header", filename);
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "%s: invalid header", filename);
|
||||
else
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
|
||||
"invalid gvdb header");
|
||||
g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "invalid gvdb header");
|
||||
|
||||
g_slice_free (GvdbTable, file);
|
||||
|
||||
if (unref)
|
||||
unref (user_data);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gvdb_table_setup_root (file, &header->root);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user