exfat: avoid overflow in Volume::ClusterToBlock().

This commit is contained in:
Jérôme Duval
2019-02-22 18:38:52 +01:00
parent a54fc27a11
commit 14263044aa
2 changed files with 6 additions and 4 deletions
@@ -1,6 +1,6 @@
/*
* Copyright 2008-2010, Axel Dörfler, [email protected].
* Copyright 2011, Jérôme Duval, [email protected].
* Copyright 2011-2019, Jérôme Duval, [email protected].
* Copyright 2014 Haiku, Inc. All rights reserved.
*
* Distributed under the terms of the MIT License.
@@ -416,9 +416,10 @@ Volume::LoadSuperBlock()
status_t
Volume::ClusterToBlock(cluster_t cluster, fsblock_t &block)
{
if (cluster < 2)
if (cluster < EXFAT_FIRST_DATA_CLUSTER)
return B_BAD_VALUE;
block = ((cluster - 2) << SuperBlock().BlocksPerClusterShift())
block = ((fsblock_t)(cluster - EXFAT_FIRST_DATA_CLUSTER)
<< SuperBlock().BlocksPerClusterShift())
+ SuperBlock().FirstDataBlock();
TRACE("Volume::ClusterToBlock() cluster %" B_PRIu32 " %u %" B_PRIu32 ": %"
B_PRIu64 ", %" B_PRIu32 "\n", cluster,
@@ -1,5 +1,5 @@
/*
* Copyright 2011, Jérôme Duval, [email protected].
* Copyright 2011-2019, Jérôme Duval, [email protected].
* Copyright 2014 Haiku, Inc. All Rights reserved.
*
* Distributed under the terms of the MIT License.
@@ -26,6 +26,7 @@ typedef uint32 cluster_t;
#define EXFAT_SUPER_BLOCK_OFFSET 0x0
#define EXFAT_FIRST_DATA_CLUSTER 2
struct exfat_super_block {