Improved the check for a valid $MFTMirr

The test for a valid $MFTMirr could segfault on a badly damaged partition.
Add safety checks.
This commit is contained in:
Jean-Pierre André 2015-09-30 09:02:15 +02:00
parent 94f8d2128e
commit 9f22e17a16

View File

@ -910,6 +910,7 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags)
ATTR_RECORD *a;
VOLUME_INFORMATION *vinf;
ntfschar *vname;
u32 record_size;
int i, j, eo;
unsigned int k;
u32 u;
@ -989,7 +990,10 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags)
goto io_error_exit;
}
}
if (memcmp(mrec, mrec2, ntfs_mft_record_get_data_size(mrec))) {
record_size = ntfs_mft_record_get_data_size(mrec);
if ((record_size <= sizeof(MFT_RECORD))
|| (record_size > vol->mft_record_size)
|| memcmp(mrec, mrec2, record_size)) {
ntfs_log_error("$MFTMirr does not match $MFT (record "
"%d).\n", i);
goto io_error_exit;