Commits

Christophe Grenier  committed faceca8

HFS and HFS+ blocksize must be a multiple of 512

  • Participants
  • Parent commits 3badc43

Comments (0)

Files changed (2)

   /* Check for HFS signature */
   if (hfs_mdb->drSigWord!=be16(HFS_SUPER_MAGIC))
     return 1;
-  /* Check for valid blocksize */
-  if(be32(hfs_mdb->drAlBlkSiz)%512!=0 || be32(hfs_mdb->drAlBlkSiz)==0)
+  /* Blocksize must be a multiple of 512 */
+  if(be32(hfs_mdb->drAlBlkSiz)<512 ||
+      ((be32(hfs_mdb->drAlBlkSiz)-1) & be32(hfs_mdb->drAlBlkSiz))!=0)
     return 1;
   /* Check for valid number of allocation blocks */
   if(be16(hfs_mdb->drNmAlBlks)==0)
 
 int test_HFSP(disk_t *disk_car, const struct hfsp_vh *vh,partition_t *partition,const int verbose, const int dump_ind)
 {
-  if (!(be32(vh->blocksize)%512==0 && be32(vh->blocksize)!=0 && be32(vh->free_blocks)<=be32(vh->total_blocks)))
+  if (be32(vh->free_blocks) > be32(vh->total_blocks))
+    return 1;
+  /* Blocksize must be a multiple of 512 */
+  if (be32(vh->blocksize)<512 ||
+      ((be32(vh->blocksize)-1) & be32(vh->blocksize))!=0)
     return 1;
   /* http://developer.apple.com/technotes/tn/tn1150.html */
   if (be16(vh->version)==4 && vh->signature==be16(HFSP_VOLHEAD_SIG))