This is why Onedrive is so much superior to iCloud.
First, it has file history. Even if you upload multiple ransomware-encrypted versions of your files to Onedrive before you realize it, you can go back until you find an unencrypted version. I believe by default the file versions limit is set to 500.
Second, it will send you an alert email if it detects ransomware-like activity in your account, such as deleting a large number of files and replacing them with encrypted files. I get alerts every time I add a bunch of files to Cryptomator because it behaves in the same way. (It will also alert you if you delete a large number of files without any encryption).
By comparison, iCloud doesn't have any such protections - at least none that I know of. If you override a file even once it's gone.