diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c index 1c7791b02..361e5be49 100644 --- a/grub-core/fs/hfsplus.c +++ b/grub-core/fs/hfsplus.c @@ -177,6 +177,17 @@ grub_hfsplus_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) break; } + /* + * If the extent overflow tree isn't ready yet, we can't look + * in it. This can happen where the catalog file is corrupted. + */ + if (!node->data->extoverflow_tree_ready) + { + grub_error (GRUB_ERR_BAD_FS, + "attempted to read extent overflow tree before loading"); + break; + } + /* Set up the key to look for in the extent overflow file. */ extoverflow.extkey.fileid = node->fileid; extoverflow.extkey.type = 0; @@ -241,6 +252,7 @@ grub_hfsplus_mount (grub_disk_t disk) return 0; data->disk = disk; + data->extoverflow_tree_ready = 0; /* Read the bootblock. */ grub_disk_read (disk, GRUB_HFSPLUS_SBLOCK, 0, sizeof (volheader), @@ -357,6 +369,8 @@ grub_hfsplus_mount (grub_disk_t disk) if (data->extoverflow_tree.nodesize < 2) goto fail; + data->extoverflow_tree_ready = 1; + if (grub_hfsplus_read_file (&data->attr_tree.file, 0, 0, sizeof (struct grub_hfsplus_btnode), sizeof (header), (char *) &header) <= 0) diff --git a/include/grub/hfsplus.h b/include/grub/hfsplus.h index 117740ae2..e14dd31ff 100644 --- a/include/grub/hfsplus.h +++ b/include/grub/hfsplus.h @@ -113,6 +113,8 @@ struct grub_hfsplus_data struct grub_hfsplus_btree extoverflow_tree; struct grub_hfsplus_btree attr_tree; + int extoverflow_tree_ready; + struct grub_hfsplus_file dirroot; struct grub_hfsplus_file opened_file;