From 1b8463f2c42e5fa2b300ccb4fa5eb416abe5a034 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 4 May 2012 17:37:17 +0200 Subject: [PATCH] Fix errors on compressed NTFS with 512B clusters. * include/grub/ntfs.h (grub_ntfscomp_func_t): Use appropriately sized types. * grub-core/fs/ntfs.c (grub_ntfs_read): Return correct -1 on error and not 0. * grub-core/fs/ntfscomp.c (read_block): Use appropriately-sized types. Relax check for inline extents. (ntfscomp): Return correct -1 on error and not 0. --- ChangeLog | 12 ++++++++++++ grub-core/fs/ntfs.c | 2 +- grub-core/fs/ntfscomp.c | 13 +++++++------ include/grub/ntfs.h | 6 +++--- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index d46d7f100..a76e378c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2012-05-04 Vladimir Serbinenko + + Fix errors on compressed NTFS with 512B clusters. + + * include/grub/ntfs.h (grub_ntfscomp_func_t): Use appropriately sized + types. + * grub-core/fs/ntfs.c (grub_ntfs_read): Return correct -1 on error and + not 0. + * grub-core/fs/ntfscomp.c (read_block): Use appropriately-sized types. + Relax check for inline extents. + (ntfscomp): Return correct -1 on error and not 0. + 2012-05-04 Vladimir Serbinenko * util/grub-install.in: Fix handling of prefix containing spaces. diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c index 30293ddfe..eb831a149 100644 --- a/grub-core/fs/ntfs.c +++ b/grub-core/fs/ntfs.c @@ -1121,7 +1121,7 @@ grub_ntfs_read (grub_file_t file, char *buf, grub_size_t len) mft->attr.save_pos = 1; read_attr (&mft->attr, buf, file->offset, len, 1, file->read_hook); - return (grub_errno) ? 0 : len; + return (grub_errno) ? -1 : (grub_ssize_t) len; } static grub_err_t diff --git a/grub-core/fs/ntfscomp.c b/grub-core/fs/ntfscomp.c index 890faa3bf..88e3ee582 100644 --- a/grub-core/fs/ntfscomp.c +++ b/grub-core/fs/ntfscomp.c @@ -176,18 +176,19 @@ decomp_block (struct grub_ntfs_comp *cc, char *dest) } static grub_err_t -read_block (struct grub_ntfs_rlst *ctx, char *buf, int num) +read_block (struct grub_ntfs_rlst *ctx, char *buf, grub_size_t num) { int cpb = GRUB_NTFS_COM_SEC / ctx->comp.spc; while (num) { - int nn; + grub_size_t nn; if ((ctx->target_vcn & 0xF) == 0) { - if (ctx->comp.comp_head != ctx->comp.comp_tail) + if (ctx->comp.comp_head != ctx->comp.comp_tail + && !(ctx->flags & GRUB_NTFS_RF_BLNK)) return grub_error (GRUB_ERR_BAD_FS, "invalid compression block"); ctx->comp.comp_head = ctx->comp.comp_tail = 0; ctx->comp.cbuf_vcn = ctx->target_vcn; @@ -243,7 +244,7 @@ read_block (struct grub_ntfs_rlst *ctx, char *buf, int num) nn *= cpb; while ((ctx->comp.comp_head < ctx->comp.comp_tail) && (nn)) { - int tt; + grub_disk_addr_t tt; tt = ctx->comp.comp_table[ctx->comp.comp_head][0] - @@ -287,8 +288,8 @@ read_block (struct grub_ntfs_rlst *ctx, char *buf, int num) } static grub_err_t -ntfscomp (struct grub_ntfs_attr *at, char *dest, grub_uint32_t ofs, - grub_uint32_t len, struct grub_ntfs_rlst *ctx, grub_uint32_t vcn) +ntfscomp (struct grub_ntfs_attr *at, char *dest, grub_disk_addr_t ofs, + grub_size_t len, struct grub_ntfs_rlst *ctx, grub_disk_addr_t vcn) { grub_err_t ret; diff --git a/include/grub/ntfs.h b/include/grub/ntfs.h index 5cdd5f73f..0ecbce95d 100644 --- a/include/grub/ntfs.h +++ b/include/grub/ntfs.h @@ -181,10 +181,10 @@ struct grub_ntfs_rlst typedef grub_err_t (*grub_ntfscomp_func_t) (struct grub_ntfs_attr * at, char *dest, - grub_uint32_t ofs, - grub_uint32_t len, + grub_disk_addr_t ofs, + grub_size_t len, struct grub_ntfs_rlst * ctx, - grub_uint32_t vcn); + grub_disk_addr_t vcn); extern grub_ntfscomp_func_t grub_ntfscomp_func;