diff --git a/src/add-ons/kernel/file_systems/exfat/DataStream.cpp b/src/add-ons/kernel/file_systems/exfat/DataStream.cpp index 5a9647e7c8..f1123c1954 100644 --- a/src/add-ons/kernel/file_systems/exfat/DataStream.cpp +++ b/src/add-ons/kernel/file_systems/exfat/DataStream.cpp @@ -52,7 +52,8 @@ DataStream::FindBlock(off_t pos, off_t& physical, off_t *_length) for (uint32 i = 0; i < clusterIndex; i++) cluster = fInode->NextCluster(cluster); fsblock_t block; - fVolume->ClusterToBlock(cluster, block); + if (fVolume->ClusterToBlock(cluster, block) != B_OK) + return B_BAD_DATA; physical = block * kBlockSize + offset; for (uint32 i = 0; i < 64; i++) { cluster_t extentEnd = fInode->NextCluster(cluster); diff --git a/src/add-ons/kernel/file_systems/exfat/DirectoryIterator.cpp b/src/add-ons/kernel/file_systems/exfat/DirectoryIterator.cpp index 278af03b1e..24e81d1c53 100644 --- a/src/add-ons/kernel/file_systems/exfat/DirectoryIterator.cpp +++ b/src/add-ons/kernel/file_systems/exfat/DirectoryIterator.cpp @@ -275,7 +275,8 @@ DirectoryIterator::_NextEntry() { if (fCurrent == NULL) { fsblock_t block; - fInode->GetVolume()->ClusterToBlock(fCluster, block); + if (fInode->GetVolume()->ClusterToBlock(fCluster, block) != B_OK) + return B_BAD_DATA; block += (fOffset / fInode->GetVolume()->EntriesPerBlock()) % (1 << fInode->GetVolume()->SuperBlock().BlocksPerClusterShift()); TRACE("DirectoryIterator::_NextEntry() init to block %" B_PRIu64 "\n", @@ -289,7 +290,8 @@ DirectoryIterator::_NextEntry() if (fCluster == EXFAT_CLUSTER_END) return B_ENTRY_NOT_FOUND; - fInode->GetVolume()->ClusterToBlock(fCluster, block); + if (fInode->GetVolume()->ClusterToBlock(fCluster, block) != B_OK) + return B_BAD_DATA; } else block = fBlock.BlockNumber() + 1; diff --git a/src/add-ons/kernel/file_systems/exfat/Volume.cpp b/src/add-ons/kernel/file_systems/exfat/Volume.cpp index aa9dbbe5e3..b6f7b1a7f3 100644 --- a/src/add-ons/kernel/file_systems/exfat/Volume.cpp +++ b/src/add-ons/kernel/file_systems/exfat/Volume.cpp @@ -416,8 +416,10 @@ Volume::LoadSuperBlock() status_t Volume::ClusterToBlock(cluster_t cluster, fsblock_t &block) { - if (cluster < EXFAT_FIRST_DATA_CLUSTER) + if ((cluster - EXFAT_FIRST_DATA_CLUSTER) >= SuperBlock().ClusterCount() + || cluster < EXFAT_FIRST_DATA_CLUSTER) { return B_BAD_VALUE; + } block = ((fsblock_t)(cluster - EXFAT_FIRST_DATA_CLUSTER) << SuperBlock().BlocksPerClusterShift()) + SuperBlock().FirstDataBlock(); diff --git a/src/add-ons/kernel/file_systems/exfat/exfat.h b/src/add-ons/kernel/file_systems/exfat/exfat.h index b33888eb46..09a7d326ea 100644 --- a/src/add-ons/kernel/file_systems/exfat/exfat.h +++ b/src/add-ons/kernel/file_systems/exfat/exfat.h @@ -170,7 +170,7 @@ struct exfat_entry { void SetFlag(uint8 newFlag) { flag = newFlag; } uint64 Size() const - { return B_LENDIAN_TO_HOST_INT64(size1); } + { return B_LENDIAN_TO_HOST_INT64(size2); } } _PACKED file_info; struct { uint8 flags;