2009-06-10 Pavel Roskin <proski@gnu.org>

* io/gzio.c (test_header): Don't reuse one buffer for all data.
	Use separate variables.  Read only the file size at the end, but
	not the checksum that we don't use.
This commit is contained in:
proski 2009-06-11 01:06:39 +00:00
parent 5c5215d5e2
commit 5ac35b35b0
2 changed files with 27 additions and 14 deletions

View file

@ -1,5 +1,9 @@
2009-06-10 Pavel Roskin <proski@gnu.org> 2009-06-10 Pavel Roskin <proski@gnu.org>
* io/gzio.c (test_header): Don't reuse one buffer for all data.
Use separate variables. Read only the file size at the end, but
not the checksum that we don't use.
* kern/file.c (grub_file_read): Use void pointer for the buffer. * kern/file.c (grub_file_read): Use void pointer for the buffer.
Adjust all callers. Adjust all callers.

View file

@ -164,7 +164,16 @@ typedef unsigned long ulg;
static int static int
test_header (grub_file_t file) test_header (grub_file_t file)
{ {
unsigned char buf[10] __attribute__ ((aligned)); struct {
grub_uint16_t magic;
grub_uint8_t method;
grub_uint8_t flags;
grub_uint32_t timestamp;
grub_uint8_t extra_flags;
grub_uint8_t os_type;
} hdr;
grub_uint16_t extra_len;
grub_uint32_t orig_len;
grub_gzio_t gzio = file->data; grub_gzio_t gzio = file->data;
if (grub_file_tell (gzio->file) != 0) if (grub_file_tell (gzio->file) != 0)
@ -175,9 +184,9 @@ test_header (grub_file_t file)
* (other than a real error with the disk) then we don't think it * (other than a real error with the disk) then we don't think it
* is a compressed file, and simply mark it as such. * is a compressed file, and simply mark it as such.
*/ */
if (grub_file_read (gzio->file, buf, 10) != 10 if (grub_file_read (gzio->file, &hdr, 10) != 10
|| ((*((grub_uint16_t *) buf) != GZIP_MAGIC) || ((hdr.magic != GZIP_MAGIC)
&& (*((grub_uint16_t *) buf) != OLD_GZIP_MAGIC))) && (hdr.magic != OLD_GZIP_MAGIC)))
{ {
grub_error (GRUB_ERR_BAD_FILE_TYPE, "no gzip magic found"); grub_error (GRUB_ERR_BAD_FILE_TYPE, "no gzip magic found");
return 0; return 0;
@ -188,14 +197,14 @@ test_header (grub_file_t file)
* problem occurs from here on, then we have corrupt or otherwise * problem occurs from here on, then we have corrupt or otherwise
* bad data, and the error should be reported to the user. * bad data, and the error should be reported to the user.
*/ */
if (buf[2] != DEFLATED if (hdr.method != DEFLATED
|| (buf[3] & UNSUPPORTED_FLAGS) || (hdr.flags & UNSUPPORTED_FLAGS)
|| ((buf[3] & EXTRA_FIELD) || ((hdr.flags & EXTRA_FIELD)
&& (grub_file_read (gzio->file, buf, 2) != 2 && (grub_file_read (gzio->file, &extra_len, 2) != 2
|| eat_field (gzio->file, || eat_field (gzio->file,
grub_le_to_cpu16 (*((grub_uint16_t *) buf))))) grub_le_to_cpu16 (extra_len))))
|| ((buf[3] & ORIG_NAME) && eat_field (gzio->file, -1)) || ((hdr.flags & ORIG_NAME) && eat_field (gzio->file, -1))
|| ((buf[3] & COMMENT) && eat_field (gzio->file, -1))) || ((hdr.flags & COMMENT) && eat_field (gzio->file, -1)))
{ {
grub_error (GRUB_ERR_BAD_GZIP_DATA, "unsupported gzip format"); grub_error (GRUB_ERR_BAD_GZIP_DATA, "unsupported gzip format");
return 0; return 0;
@ -203,9 +212,9 @@ test_header (grub_file_t file)
gzio->data_offset = grub_file_tell (gzio->file); gzio->data_offset = grub_file_tell (gzio->file);
grub_file_seek (gzio->file, grub_file_size (gzio->file) - 8); grub_file_seek (gzio->file, grub_file_size (gzio->file) - 4);
if (grub_file_read (gzio->file, buf, 8) != 8) if (grub_file_read (gzio->file, &orig_len, 4) != 4)
{ {
grub_error (GRUB_ERR_BAD_FILE_TYPE, "unsupported gzip format"); grub_error (GRUB_ERR_BAD_FILE_TYPE, "unsupported gzip format");
return 0; return 0;
@ -213,7 +222,7 @@ test_header (grub_file_t file)
/* FIXME: this does not handle files whose original size is over 4GB. /* FIXME: this does not handle files whose original size is over 4GB.
But how can we know the real original size? */ But how can we know the real original size? */
file->size = grub_le_to_cpu32 (*((grub_uint32_t *) (buf + 4))); file->size = grub_le_to_cpu32 (orig_len);
initialize_tables (file); initialize_tables (file);