From bb0168e56baa1d7e33eec49ee36866eb2f7806bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Mon, 17 May 2021 15:33:41 +0300 Subject: [PATCH] Rejected updates of uninitialized MFTMirr Reject updating uninitialized MFTMirr because it leads to endless recursions as updating the MFTMirr entry of MFT implies further updating MFTMirr. This is probably specific to ntfsfix, as mounts are normally rejected when MFTMirr does not match MFT. --- libntfs-3g/mft.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libntfs-3g/mft.c b/libntfs-3g/mft.c index a80d1e4e..33b832a9 100644 --- a/libntfs-3g/mft.c +++ b/libntfs-3g/mft.c @@ -172,6 +172,15 @@ int ntfs_mft_records_write(const ntfs_volume *vol, const MFT_REF mref, cnt = vol->mftmirr_size - m; if (cnt > count) cnt = count; + if ((m + cnt) > vol->mftmirr_na->initialized_size >> + vol->mft_record_size_bits) { + errno = ESPIPE; + ntfs_log_perror("Trying to write non-allocated mftmirr" + " records (%lld > %lld)", (long long)m + cnt, + (long long)vol->mftmirr_na->initialized_size >> + vol->mft_record_size_bits); + return -1; + } bmirr = ntfs_malloc(cnt * vol->mft_record_size); if (!bmirr) return -1;