Failed: File length is invalid Details: System.Security.Cryptography.CryptographicException: File length is invalid ---> System.IO.InvalidDataException: File length is invalid

Failed: File length is invalid
Details: System.Security.Cryptography.CryptographicException: File length is invalid —> System.IO.InvalidDataException: File length is invalid

Getting this error on many backups, running a repair and rerunning the task (sometimes 3 or 4 times) will get past the error for a successful task execution.

How do we stop this error occurring? Backups are supposed to be entirely automated and having to manually rerun when this error occurs obviously ruins that.

What version of Duplicati are you using? I cannot find that exact text in the source code anymore.
I am a little confused that there is both InvalidDataException and CryptographicException reported. Is this a copy-paste of the error message?

The error message indicates that either transfers or storage are unreliable. The stored file should be exactly the same when read back, and this error message indicates that it has be truncated somehow.

FWIW that seems common. Google “Duplicati” “CryptographicException” “InvalidDataException”

This is happening on 2.0.7.1_beta_2023-05-25 which we have been using without any problems since just after its release, it is only within the last month or so that this error has started to appear across many configurations. That part is a small extract of the error, below is how it is sent to our email in its entirety:

Failed: File length is invalid
Details: System.Security.Cryptography.CryptographicException: File length is invalid ---> System.IO.InvalidDataException: File length is invalid
at SharpAESCrypt.SharpAESCrypt.Read(Byte[] buffer, Int32 offset, Int32 count)
at Duplicati.Library.Utility.Utility.CopyStream(Stream source, Stream target, Boolean tryRewindSource, Byte[] buf)
at Duplicati.Library.Encryption.EncryptionBase.Decrypt(Stream input, Stream output)
at Duplicati.Library.Main.BackendManager.<>c__DisplayClass33_0.<coreDoGetPiping>b__0()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
at Duplicati.Library.Main.AsyncDownloader.AsyncDownloaderEnumerator.AsyncDownloadedFile.get_TempFile()
at Duplicati.Library.Main.Operation.CompactHandler.DoCompact(LocalDeleteDatabase db, Boolean hasVerifiedBackend, IDbTransaction& transaction, BackendManager sharedBackend)
at Duplicati.Library.Main.Operation.DeleteHandler.DoRun(LocalDeleteDatabase db, IDbTransaction& transaction, Boolean hasVerifiedBackend, Boolean forceCompact, BackendManager sharedManager)
at Duplicati.Library.Main.Operation.BackupHandler.CompactIfRequired(BackendManager backend, Int64 lastVolumeSize)
at Duplicati.Library.Main.Operation.BackupHandler.<RunAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at CoCoL.ChannelExtensions.WaitForTaskOrThrow(Task task)
at Duplicati.Library.Main.Controller.<>c__DisplayClass14_0.<Backup>b__0(BackupResults result)
at Duplicati.Library.Main.Controller.RunAction[T](T result, String[]& paths, IFilter& filter, Action`1 method)

Log data:
2025-01-16 04:49:05 -06 - [Error-Duplicati.Library.Main.AsyncDownloader-FailedToRetrieveFile]: Failed to retrieve file duplicati-be777ce276b6b492885a4b3b11bb60200.dblock.zip.aes
System.Security.Cryptography.CryptographicException: File length is invalid ---> System.IO.InvalidDataException: File length is invalid
at SharpAESCrypt.SharpAESCrypt.Read(Byte[] buffer, Int32 offset, Int32 count)
at Duplicati.Library.Utility.Utility.CopyStream(Stream source, Stream target, Boolean tryRewindSource, Byte[] buf)
at Duplicati.Library.Encryption.EncryptionBase.Decrypt(Stream input, Stream output)
at Duplicati.Library.Main.BackendManager.<>c__DisplayClass33_0.<coreDoGetPiping>b__0()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
at Duplicati.Library.Main.BackendManager.FileEntryItem.Duplicati.Library.Main.BackendManager.IDownloadWaitHandle.Wait(String& hash, Int64& size)
at Duplicati.Library.Main.AsyncDownloader.AsyncDownloaderEnumerator.MoveNext()
2025-01-16 04:49:25 -06 - [Error-Duplicati.Library.Main.Operation.BackupHandler-FatalError]: Fatal error
System.Security.Cryptography.CryptographicException: File length is invalid ---> System.IO.InvalidDataException: File length is invalid
at SharpAESCrypt.SharpAESCrypt.Read(Byte[] buffer, Int32 offset, Int32 count)
at Duplicati.Library.Utility.Utility.CopyStream(Stream source, Stream target, Boolean tryRewindSource, Byte[] buf)
at Duplicati.Library.Encryption.EncryptionBase.Decrypt(Stream input, Stream output)
at Duplicati.Library.Main.BackendManager.<>c__DisplayClass33_0.<coreDoGetPiping>b__0()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
at Duplicati.Library.Main.AsyncDownloader.AsyncDownloaderEnumerator.AsyncDownloadedFile.get_TempFile()
at Duplicati.Library.Main.Operation.CompactHandler.DoCompact(LocalDeleteDatabase db, Boolean hasVerifiedBackend, IDbTransaction& transaction, BackendManager sharedBackend)
at Duplicati.Library.Main.Operation.DeleteHandler.DoRun(LocalDeleteDatabase db, IDbTransaction& transaction, Boolean hasVerifiedBackend, Boolean forceCompact, BackendManager sharedManager)
at Duplicati.Library.Main.Operation.BackupHandler.CompactIfRequired(BackendManager backend, Int64 lastVolumeSize)
at Duplicati.Library.Main.Operation.BackupHandler.<RunAsync>d__20.MoveNext()

Ok, that explains it. I found the error message in the previous SharpAESCrypt library. It can happen for 3 different reasons, but all of them suggests the same: the file has been truncated.

This error mentions duplicati-be777ce276b6b492885a4b3b11bb60200.dblock.zip.aes, can you locate that file and see if anything appears odd?
Particularly, see if it has been modified somehow (timestamp, file size, other indicators).

If you see this across multiple backups, could it be an issue with the storage?

I could not recall which particular server that error came from, but a new one came through today either way to check with the same issue.

Checking the remote the file size is definitely smaller than it should be for the file it mentions, 334MB in this case VS the 500MB it should be. Last modified is 19th December, to note our retention is 14 days, a few other files exist outside of the retention window though so I’m unsure of the significance there. Other than that I cannot really see anything unusual.

I would say 75-80% of my other servers are running backups using the same remote/configuration without any problems so I did not suspect the remote to be problematic.

You also have to look at file sequence by date. Last dblock will likely only be partly filled.

Test says append does it too. Regardless, it seems like some bad form exists with the file.

Once compact decides that some volumes have too much wasted space (so need compact). repeated runs should download the same volumes. Maybe you could check your log files for "RetryAttempts" value in Job → Show log → Complete log to see if retrying led to success.

1 Like